Files
.emacs.d/core/siren-core.el
Jim Myhrberg 7557a1cf1e Switch from move-text to move-dup package
This allows me to remove the custom method for duplicating line, as
move-dup comes with a nice implementation.
2016-03-29 13:34:39 +01:00

84 lines
2.4 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-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