mirror of
https://github.com/jimeh/.emacs.d.git
synced 2026-02-19 13:46:41 +00:00
feat(editor): add custom yank-indent package
When yank-indent-mode is enabled, yanked (pasted) text is indented based on the indent rules of the current major mode. It has a global-yank-indent-mode too which by default excludes a long list of known indentation sensitive modes with which this approach does not work very well. It is based on some random hacky snippets elisp I've been using for over a decade. Said snippets are themselves based on some random snippets I found online, and since morphed into the weird monster they had become.
This commit is contained in:
@@ -12,25 +12,6 @@
|
||||
"Basic settings for Siren."
|
||||
:group 'tools)
|
||||
|
||||
(defcustom siren-yank-indent-threshold 1000
|
||||
"Threshold (# chars) over which indentation does not automatically occur."
|
||||
:type 'number
|
||||
:group 'siren)
|
||||
|
||||
(defcustom siren-indent-sensitive-modes
|
||||
'(coffee-mode conf-mode haml-mode makefile-automake-mode makefile-bsdmake-mode
|
||||
makefile-gmake-mode makefile-imake-mode makefile-makepp-mode
|
||||
makefile-mode python-mode slim-mode yaml-mode)
|
||||
"Major modes for which auto-indenting is suppressed."
|
||||
:type '(repeat symbol)
|
||||
:group 'siren)
|
||||
|
||||
(defcustom siren-yank-indent-modes '(LaTeX-mode TeX-mode)
|
||||
"Major modes in which to indent regions that are yanked (or yank-popped).
|
||||
Only modes that don't derive from `prog-mode' should be listed here."
|
||||
:type '(repeat symbol)
|
||||
:group 'siren)
|
||||
|
||||
(defcustom siren-transparency-level 99
|
||||
"The default frame transparency level for Emacs frames."
|
||||
:type 'number
|
||||
|
||||
@@ -95,32 +95,6 @@
|
||||
(put 'upcase-region 'disabled nil)
|
||||
(put 'downcase-region 'disabled nil)
|
||||
|
||||
;; automatically indenting yanked text if in programming-modes
|
||||
(defun yank-advised-indent-function (beg end)
|
||||
"Do indentation, as long as the region isn't too large."
|
||||
(if (<= (- end beg) siren-yank-indent-threshold)
|
||||
(indent-region beg end nil)))
|
||||
|
||||
(defmacro advise-commands (advice-name commands class &rest body)
|
||||
"Apply advice named ADVICE-NAME to multiple COMMANDS.
|
||||
|
||||
The body of the advice is in BODY."
|
||||
`(progn
|
||||
,@(mapcar (lambda (command)
|
||||
`(defadvice ,command (,class ,(intern (concat (symbol-name command) "-" advice-name)) activate)
|
||||
,@body))
|
||||
commands)))
|
||||
|
||||
(advise-commands "indent" (yank yank-pop) after
|
||||
"If current mode is one of `siren-yank-indent-modes',
|
||||
indent yanked text (with prefix arg don't indent)."
|
||||
(if (and (not (ad-get-arg 0))
|
||||
(not (member major-mode siren-indent-sensitive-modes))
|
||||
(or (derived-mode-p 'prog-mode)
|
||||
(member major-mode siren-yank-indent-modes)))
|
||||
(let ((transient-mark-mode nil))
|
||||
(yank-advised-indent-function (region-beginning) (region-end)))))
|
||||
|
||||
;; make a shell script executable automatically on save
|
||||
(add-hook 'after-save-hook
|
||||
'executable-make-buffer-file-executable-if-script-p)
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
(require 'siren-vundo)
|
||||
(require 'siren-which-key)
|
||||
(require 'siren-whitespace)
|
||||
(require 'siren-yank-indent)
|
||||
|
||||
;; Completion Systems and Interfaces
|
||||
(require 'siren-vertico)
|
||||
|
||||
Reference in New Issue
Block a user