mirror of
https://github.com/jimeh/.emacs.d.git
synced 2026-02-19 13:46:41 +00:00
I've taken a lot of inspiration from Emacs-Prelude when it came to the structure of this rewritten config. I didn't want to use Prelude as I don't agree with all it's defaults, nor do I want to have to deal with any future changes in Prelude that might break things for me. So instead I went down the fully custom path, but heavily inspired by Prelude, both in terms of file/code structure, and also some of it's features. Compared to my old config setup, it's got most of the same things, but nearly everything is in a module file now, making it easy to fully enable/disable certain features.
107 lines
2.6 KiB
EmacsLisp
107 lines
2.6 KiB
EmacsLisp
;;
|
|
;; 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) |