;; ;; helpers ;; ;; ;; Duplicate Line ;; - from: http://tuxicity.se/emacs/elisp/2010/03/11/duplicate-current-line-or-region-in-emacs.html ;; (defun 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." (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))))) ;; ;; Align Equal Signs ;; (defun align-region-to-equals (begin end) "Align region to equal signs" (interactive "r") (align-regexp begin end "\\(\\s-*\\)=" 1 1 )) (defun align-region-to-opening-brace (begin end) "Align region to equal signs" (interactive "r") (align-regexp begin end "\\(\\s-*\\){" 1 1 )) ;; ;; Yank Pop Forwards ;; (defun yank-pop-forwards (arg) (interactive "p") (yank-pop (- arg))) ;; ;; Window Switching ;; (defun other-window-reverse () "Switch to the previous window" (interactive) (other-window -1)) ;; ;; HideShow mode helpers ;; - from: http://www.emacswiki.org/emacs/HideShow ;; (defun toggle-selective-display (column) (interactive "P") (set-selective-display (or column (unless selective-display (1+ (current-column)))))) (defun toggle-hiding (column) (interactive "P") (if hs-minor-mode (if (condition-case nil (hs-toggle-hiding) (error t)) (hs-show-all)) (toggle-selective-display column))) ;; ;; File and Buffer Renaming ;; - from: http://emacsredux.com/blog/2013/05/04/rename-file-and-buffer/ ;; (defun rename-file-and-buffer () "Rename the current buffer and file it is visiting." (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-helpers)