mirror of
https://github.com/jimeh/.emacs.d.git
synced 2026-02-19 13:46:41 +00:00
106 lines
3.3 KiB
EmacsLisp
106 lines
3.3 KiB
EmacsLisp
;;; siren-core.el --- jimeh's Emacs Siren: Core Siren functions.
|
|
|
|
;;; Commentary:
|
|
|
|
;; Core Siren functions used a bit all over the place. Some of them shamelessly
|
|
;; ripped from Emacs Prelude.
|
|
|
|
;;; Code:
|
|
|
|
(defun siren-smart-open-line-above ()
|
|
"Insert an empty line above the current line.
|
|
Position the cursor at it's beginning, according to the current mode."
|
|
(interactive)
|
|
(move-beginning-of-line nil)
|
|
(newline-and-indent)
|
|
(forward-line -1)
|
|
(indent-according-to-mode))
|
|
|
|
(defun siren-wrap-with (s)
|
|
"Create a wrapper function for smartparens using S."
|
|
`(lambda (&optional arg)
|
|
(interactive "P")
|
|
(sp-wrap-with-pair ,s)))
|
|
|
|
(defun siren-align-region-to-equals (begin end)
|
|
"Align region (specified with BEGIN and END) to equal signs."
|
|
(interactive "r")
|
|
(align-regexp begin end "\\(\\s-*\\)=" 1 1 ))
|
|
|
|
(defun siren-align-region-to-opening-brace (begin end)
|
|
"Align region (specified with BEGIN and END) to equal opening brace."
|
|
(interactive "r")
|
|
(align-regexp begin end "\\(\\s-*\\){" 1 1 ))
|
|
|
|
(defun siren-yank-pop-forwards (arg)
|
|
"Yank pop in reverse."
|
|
(interactive "p")
|
|
(yank-pop (- arg)))
|
|
|
|
(defun siren-other-window-reverse ()
|
|
"Switch to the previous window."
|
|
(interactive)
|
|
(other-window -1))
|
|
|
|
(defun siren-duplicate-current-line-or-region (arg)
|
|
"Duplicates the current line or region ARG times.
|
|
If there's no region, the current line will be duplicated. However, if
|
|
there's a region, all lines that region covers will be duplicated.
|
|
|
|
Borrowed from: http://tuxicity.se/emacs/elisp/2010/03/11/duplicate-current-line-or-region-in-emacs.html"
|
|
(interactive "p")
|
|
(let (beg end (origin (point)))
|
|
(if (and mark-active (> (point) (mark)))
|
|
(exchange-point-and-mark))
|
|
(setq beg (line-beginning-position))
|
|
(if mark-active
|
|
(exchange-point-and-mark))
|
|
(setq end (line-end-position))
|
|
(let ((region (buffer-substring-no-properties beg end)))
|
|
(dotimes (i arg)
|
|
(goto-char end)
|
|
(newline)
|
|
(insert region)
|
|
(setq end (point)))
|
|
(goto-char (+ origin (* (length region) arg) arg)))))
|
|
|
|
(defun siren-toggle-hiding (column)
|
|
"Toggle hiding/showing blocks via hs-mode.
|
|
|
|
Borrowed from: http://www.emacswiki.org/emacs/HideShow"
|
|
(interactive "P")
|
|
(if hs-minor-mode
|
|
(if (condition-case nil
|
|
(hs-toggle-hiding)
|
|
(error t))
|
|
(hs-show-all))
|
|
(siren-toggle-selective-display column)))
|
|
|
|
(defun siren-toggle-selective-display (column)
|
|
"Helper function for `siren-toggle-hiding'."
|
|
(interactive "P")
|
|
(set-selective-display
|
|
(or column
|
|
(unless selective-display
|
|
(1+ (current-column))))))
|
|
|
|
(defun siren-rename-file-and-buffer ()
|
|
"Rename the current buffer and file it is visiting.
|
|
|
|
Borrowed from: http://emacsredux.com/blog/2013/05/04/rename-file-and-buffer/"
|
|
(interactive)
|
|
(let ((filename (buffer-file-name)))
|
|
(if (not (and filename (file-exists-p filename)))
|
|
(message "Buffer is not visiting a file!")
|
|
(let ((new-name (read-file-name "New name: " filename)))
|
|
(cond
|
|
((vc-backend filename) (vc-rename-file filename new-name))
|
|
(t
|
|
(rename-file filename new-name t)
|
|
(rename-buffer new-name)
|
|
(set-visited-file-name new-name)
|
|
(set-buffer-modified-p nil)))))))
|
|
|
|
(provide 'siren-core)
|
|
;;; siren-core.el ends here
|