From 536b8b7bfd87a92aef9b78c62210e9f40c91e572 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Sat, 12 Aug 2023 09:04:19 +0800 Subject: [PATCH] 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. --- lisp/indent-aux.el | 75 ++++++++++++++++++++++++++++++++++++++++++++++ lisp/simple.el | 42 -------------------------- 2 files changed, 75 insertions(+), 42 deletions(-) create mode 100644 lisp/indent-aux.el 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 . + +;;; 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. diff --git a/lisp/simple.el b/lisp/simple.el index 561b1f7fbeb..1bc35e87554 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -11140,48 +11140,6 @@ seconds." (setq undo-auto-current-boundary-timer (run-at-time 5 nil #'undo-auto--boundary-timer))))))) - - -;; 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 'simple) ;;; simple.el ends here -- 2.39.2