diff options
author | Po Lu <luangruo@yahoo.com> | 2023-08-12 09:04:19 +0800 |
---|---|---|
committer | Po Lu <luangruo@yahoo.com> | 2023-08-12 09:04:19 +0800 |
commit | 536b8b7bfd87a92aef9b78c62210e9f40c91e572 (patch) | |
tree | 26982788405a7f5f668200a088e9d23115a26f61 /lisp/indent-aux.el | |
parent | 28ae8440c62c71da2ef7e30c73333bc5a51efba6 (diff) | |
download | emacs-536b8b7bfd87a92aef9b78c62210e9f40c91e572.tar.gz |
Make kill-ring-deindent-mode autoloaded
* lisp/indent-aux.el
(kill-ring-deindent-buffer-substring-function)
(kill-ring-deindent-mode, indent-aux):
* lisp/simple.el (kill-ring-deindent-buffer-substring-function)
(kill-ring-deindent-mode): Move kill-ring-deindent-mode to
indent-aux.el.
Diffstat (limited to 'lisp/indent-aux.el')
-rw-r--r-- | lisp/indent-aux.el | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/lisp/indent-aux.el b/lisp/indent-aux.el new file mode 100644 index 00000000000..202e426c667 --- /dev/null +++ b/lisp/indent-aux.el @@ -0,0 +1,75 @@ +;;; indent-aux.el --- Autoloaded indentation commands for Emacs -*- lexical-binding:t -*- + +;; Copyright (C) 2023 Free Software Foundation, Inc. + +;; Maintainer: emacs-devel@gnu.org +;; Package: emacs + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Autoloaded commands for making and changing indentation in text and +;; killed text + +;;; Code: + + + +;; Indent Filter mode. When enabled, this minor mode filters all +;; killed text to remove leading indentation. + +(defun kill-ring-deindent-buffer-substring-function (beg end delete) + "Save the text within BEG and END to kill-ring, decreasing indentation. +Delete the saved text if DELETE is non-nil. + +In the saved copy of the text, remove some of the indentation, such +that the buffer position at BEG will be at column zero when the text +is yanked." + (let ((a beg) + (b end)) + (setq beg (min a b) + end (max a b))) + (let ((indentation (save-excursion (goto-char beg) + (current-column))) + (text (if delete + (delete-and-extract-region beg end) + (buffer-substring beg end)))) + (with-temp-buffer + (insert text) + (indent-rigidly (point-min) (point-max) + (- indentation)) + (buffer-string)))) + +(define-minor-mode kill-ring-deindent-mode + "Toggle removal of indentation from text saved to the kill ring. + +When this minor mode is enabled, text saved into the kill ring is +indented towards the left by the column number at the start of +that text." + :global 't + :group 'killing + (if kill-ring-deindent-mode + (add-function :override filter-buffer-substring-function + #'kill-ring-deindent-buffer-substring-function + '(:depth 100)) + (remove-function filter-buffer-substring-function + #'kill-ring-deindent-buffer-substring-function))) + + + +(provide 'indent-aux) +;;; indent-aux.el ends here. |