commit f611c5be210a552256799ee95ef72a74efbfdd1d (HEAD, refs/remotes/origin/master) Author: Paul Eggert Date: Fri Aug 11 23:09:39 2023 -0700 Update lists of non-UTF files * .gitattributes: Don't diff text files with encodings incompatible with UTF-8. Add some new binary file extensions, like '.webp'. etc/e/eterm-direct and java/emacs.keystore are also binary. * admin/notes/unicode: Update similarly. diff --git a/.gitattributes b/.gitattributes index d9288b27d0f..b56f0ec617d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -17,13 +17,11 @@ # You should have received a copy of the GNU General Public License # along with GNU Emacs. If not, see . -# A few files use CRLF endings, even on non-Microsoft platforms. +# A few UTF-8-compatible text files use CRLF endings, +# even on non-Microsoft platforms. # Do not warn about trailing whitespace with these files. *.bat whitespace=cr-at-eol admin/charsets/mapfiles/PTCP154 whitespace=cr-at-eol -leim/MISC-DIC/cangjie-table.b5 whitespace=cr-at-eol -leim/MISC-DIC/cangjie-table.cns whitespace=cr-at-eol -leim/MISC-DIC/pinyin.map whitespace=cr-at-eol test/manual/etags/c-src/dostorture.c whitespace=cr-at-eol test/manual/etags/cp-src/c.C whitespace=cr-at-eol test/manual/etags/html-src/algrthms.html whitespace=cr-at-eol @@ -31,19 +29,41 @@ test/manual/etags/html-src/algrthms.html whitespace=cr-at-eol # The todo-mode file format includes trailing whitespace. *.tod[aorty] -whitespace=blank-at-eol +# The following text files use encodings incompatible with UTF-8. +# They should not be treated as text when diffing, as that could +# cause the output to mix encodings. +*.tit -diff +admin/charsets/mapfiles/cns2ucsdkw.txt -diff +leim/MISC-DIC/CTLau* -diff +leim/MISC-DIC/cangjie-table.* -diff +leim/MISC-DIC/pinyin.map -diff +leim/MISC-DIC/ziranma.cin -diff +leim/SKK-DIC/SKK-JISYO.L -diff +src/msdos.c -diff +test/lisp/gnus/mm-decode-resources/win1252-multipart.bin -diff + # Some files should not be treated as text when diffing or merging. +*.bmp binary *.cur binary +*.gif binary *.gpg binary *.gz binary *.icns binary *.ico binary +*.jpg binary +*.kbx binary +*.key binary *.pbm binary *.pdf binary *.pif binary *.png binary *.sig binary *.tiff binary +*.webp binary +*.zip binary etc/e/eterm-color binary +etc/e/eterm-direct binary +java/emacs.keystore binary # Git's builtin diff hunk header styles. *.ad[abs] diff=ada diff --git a/admin/notes/unicode b/admin/notes/unicode index b4f23f68def..da4736c43c6 100644 --- a/admin/notes/unicode +++ b/admin/notes/unicode @@ -305,6 +305,12 @@ nontrivial changes to the build process. src/msdos.c + * iso-latin-1 + + This file is used to test Emacs encoding. + + test/lisp/gnus/mm-decode-resources/win1252-multipart.bin + * iso-2022-cn-ext This file is externally generated from leim/MISC-DIC/cangjie-table.b5 @@ -355,19 +361,27 @@ nontrivial changes to the build process. Some of the entries in this list are patterns, and stand for any files with the listed extension. + *.bmp + *.cur + *.gif + *.gpg *.gz *.icns *.ico + *.jpg + *.kbx + *.key *.pbm *.pdf + *.pif *.png *.sig + *.tiff + *.webp + *.zip etc/e/eterm-color - etc/package-keyring.gpg - msdos/emacs.pif - nextstep/GNUstep/Emacs.base/Resources/emacs.tiff - nt/icons/hand.cur - + etc/e/eterm-direct + java/emacs.keystore This file is part of GNU Emacs. commit be3cae9f559015219af07dd63170dded2fb64056 Author: Stefan Monnier Date: Fri Aug 11 23:14:05 2023 -0400 * lisp/emacs-lisp/cl-macs.el (cl--labels-convert): Fix bug#65017 This fixes what I consider to be the core of the bug, by handling `cl--labels-convert-cache` more carefully (i.e. being more careful how we look up its value and by flushing it ASAP). diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index 0a3181561bd..87b6801bf00 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el @@ -2037,7 +2037,17 @@ cl--labels-convert ;; *after* handling `function', but we want to stop macroexpansion from ;; being applied infinitely, so we use a cache to return the exact `form' ;; being expanded even though we don't receive it. - ((eq f (car cl--labels-convert-cache)) (cdr cl--labels-convert-cache)) + ;; In Common Lisp, we'd use the `&whole' arg instead (see + ;; "Macro Lambda Lists" in the CLHS). + ((let ((symbols-with-pos-enabled nil)) ;Don't rewrite #' => #' + ;; FIXME: The above `let' is incorrectly optimized away (bug#65017). + (eq f (car cl--labels-convert-cache))) + ;; This value should be `eq' to the `&whole' form. + ;; If this is not the case, we have a bug. + (prog1 (cdr cl--labels-convert-cache) + ;; Drop it, so it can't accidentally interfere with some + ;; unrelated subsequent use of `function' with the same symbol. + (setq cl--labels-convert-cache nil))) (t (let* ((found (assq f macroexpand-all-environment)) (replacement (and found @@ -2045,6 +2055,8 @@ cl--labels-convert (funcall (cdr found) cl--labels-magic))))) (if (and replacement (eq cl--labels-magic (car replacement))) (nth 1 replacement) + ;; FIXME: Here, we'd like to return the `&whole' form, but since ELisp + ;; doesn't have that, we approximate it via `cl--labels-convert-cache'. (let ((res `(function ,f))) (setq cl--labels-convert-cache (cons f res)) res)))))) commit 1da4fca0647ebf1d5d6f12817301a17661560810 Author: Po Lu Date: Sat Aug 12 10:21:34 2023 +0800 Improve precision pixel scrolling * lisp/pixel-scroll.el (pixel-scroll-precision-scroll-down-page) (pixel-scroll-precision-scroll-up-page): Use pos-visible-in-window-p to opt between the next line or to the window start rather than computing the next position by hand. (pixel-scroll-precision-mode): Disable make-cursor-line-fully-visible. (bug#65214) * src/image.c (jpeg_load_body): Fix crash if libjpeg detects an error before ximg is initialized. * src/xdisp.c (display_and_set_cursor): Don't display cursor in vscrolled-away row. diff --git a/lisp/pixel-scroll.el b/lisp/pixel-scroll.el index ac867a1351c..488f6781254 100644 --- a/lisp/pixel-scroll.el +++ b/lisp/pixel-scroll.el @@ -519,38 +519,41 @@ pixel-scroll-precision-scroll-down-page (desired-vscroll (if start-posn (- delta (cdr (posn-x-y start-posn))) (+ current-vs delta))) - (edges (window-edges nil t)) - (usable-height (- (nth 3 edges) - (nth 1 edges))) - (next-pos (save-excursion - (goto-char desired-start) - (when (zerop (vertical-motion (1+ scroll-margin))) - (set-window-start nil desired-start) - (signal 'end-of-buffer nil)) - (while (when-let ((posn (posn-at-point))) - (< (cdr (posn-x-y posn)) delta)) - (when (zerop (vertical-motion 1)) - (set-window-start nil desired-start) - (signal 'end-of-buffer nil))) - (point))) (scroll-preserve-screen-position nil) - (auto-window-vscroll nil)) - (when (and (or (< (point) next-pos)) - (let ((pos-visibility (pos-visible-in-window-p next-pos nil t))) - (and pos-visibility - (or (eq (length pos-visibility) 2) - (when-let* ((posn (posn-at-point next-pos))) - (> (cdr (posn-object-width-height posn)) - usable-height)))))) - (goto-char next-pos)) - (set-window-start nil (if (zerop (window-hscroll)) - desired-start - (save-excursion - (goto-char desired-start) - (beginning-of-visual-line) - (point))) - t) - (set-window-vscroll nil desired-vscroll t t))) + (auto-window-vscroll nil) + (new-start-position (if (zerop (window-hscroll)) + desired-start + (save-excursion + (goto-char desired-start) + (beginning-of-visual-line) + (point))))) + (set-window-start nil new-start-position + (not (zerop desired-vscroll))) + (set-window-vscroll nil desired-vscroll t t) + ;; Constrain point to a location that will not result in + ;; recentering, if it is no longer completely visible. + (unless (pos-visible-in-window-p (point)) + ;; If desired-vscroll is 0, target the window start itself. But + ;; in any other case, target the line immediately below the + ;; window start, unless that line is itself invisible. This + ;; improves the appearance of the window by maintaining the + ;; cursor row in a fully visible state. + (if (zerop desired-vscroll) + (goto-char new-start-position) + (let ((line-after (save-excursion + (goto-char new-start-position) + (if (zerop (vertical-motion 1)) + (progn + (set-window-vscroll nil 0 t t) + nil) ; nil means move to new-start-position. + (point))))) + (if (not line-after) + (progn + (goto-char new-start-position) + (signal 'end-of-buffer nil)) + (if (pos-visible-in-window-p line-after nil t) + (goto-char line-after) + (goto-char new-start-position)))))))) (defun pixel-scroll-precision-scroll-down (delta) "Scroll the current window down by DELTA pixels." @@ -569,27 +572,12 @@ pixel-scroll-precision-scroll-up-page (let* ((edges (window-edges nil t nil t)) (max-y (- (nth 3 edges) (nth 1 edges))) - (usable-height max-y) (posn (posn-at-x-y 0 (+ (window-tab-line-height) (window-header-line-height) (- max-y delta)))) - (point (posn-point posn)) - (up-point (and point - (save-excursion - (goto-char point) - (vertical-motion (- (1+ scroll-margin))) - (point))))) - (when (and point (> (point) up-point)) - (when (let ((pos-visible (pos-visible-in-window-p up-point nil t))) - (or (eq (length pos-visible) 2) - (when-let* ((posn (posn-at-point up-point)) - (edges (window-edges nil t)) - (usable-height (- (nth 3 edges) - (nth 1 edges)))) - (> (cdr (posn-object-width-height posn)) - usable-height)))) - (goto-char up-point))) - (let ((current-vscroll (window-vscroll nil t))) + (point (posn-point posn))) + (let ((current-vscroll (window-vscroll nil t)) + (wanted-pos (window-start))) (setq delta (- delta current-vscroll)) (set-window-vscroll nil 0 t t) (when (> delta 0) @@ -598,16 +586,25 @@ pixel-scroll-precision-scroll-up-page start nil nil nil t)) (height (nth 1 dims)) (position (nth 2 dims))) - (set-window-start nil position t) - ;; If the line above is taller than the window height (i.e. there's - ;; a very tall image), keep point on it. - (when (> height usable-height) - (goto-char position)) + (setq wanted-pos position) (when (or (not position) (eq position start)) (signal 'beginning-of-buffer nil)) (setq delta (- delta height)))) + (set-window-start nil wanted-pos + (not (zerop delta))) (when (< delta 0) - (set-window-vscroll nil (- delta) t t))))) + (set-window-vscroll nil (- delta) t t)) + ;; vscroll and the window start are now set. Move point to a + ;; position where redisplay will not recenter, if it is now + ;; outside the window. + (unless (pos-visible-in-window-p (point)) + (let ((up-pos (save-excursion + (goto-char point) + (vertical-motion -1) + (point)))) + (if (pos-visible-in-window-p up-pos nil t) + (goto-char up-pos) + (goto-char (window-start)))))))) (defun pixel-scroll-precision-interpolate (delta &optional old-window factor) "Interpolate a scroll of DELTA pixels. @@ -860,7 +857,9 @@ pixel-scroll-precision-mode :group 'mouse :keymap pixel-scroll-precision-mode-map (setq mwheel-coalesce-scroll-events - (not pixel-scroll-precision-mode))) + (not pixel-scroll-precision-mode)) + (setq-default make-cursor-line-fully-visible + (not pixel-scroll-precision-mode))) (provide 'pixel-scroll) ;;; pixel-scroll.el ends here diff --git a/src/image.c b/src/image.c index 29e88f0d752..7849675b6cc 100644 --- a/src/image.c +++ b/src/image.c @@ -8838,7 +8838,8 @@ jpeg_load_body (struct frame *f, struct image *img, jpeg_destroy_decompress (&mgr->cinfo); /* If we already have an XImage, free that. */ - image_destroy_x_image (ximg); + if (ximg) + image_destroy_x_image (ximg); /* Free pixmap and colors. */ image_clear_image (f, img); return 0; diff --git a/src/xdisp.c b/src/xdisp.c index d055bb3bf6a..69aa9bb9c33 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -33790,6 +33790,7 @@ display_and_set_cursor (struct window *w, bool on, completely erased, to avoid the extra work of erasing the cursor twice. In other words, phys_cursor_on_p can be true and the cursor still not be visible, or it has only been partly erased. */ + if (on) { w->phys_cursor_ascent = glyph_row->ascent; @@ -33803,9 +33804,15 @@ display_and_set_cursor (struct window *w, bool on, w->phys_cursor.vpos = vpos; } - FRAME_RIF (f)->draw_window_cursor (w, glyph_row, x, y, - new_cursor_type, new_cursor_width, - on, active_cursor); + /* If make_cursor_line_fully_visible is nil and the row is in fact + vscrolled out of the window, then glyph_row->y + + glyph_row->height will be less than or equal to 0. Eschew + displaying the cursor in that case. */ + + if (MATRIX_ROW_BOTTOM_Y (glyph_row) > 0) + FRAME_RIF (f)->draw_window_cursor (w, glyph_row, x, y, + new_cursor_type, new_cursor_width, + on, active_cursor); } commit 324a109aa3add67772fdcd9fd27d4941bf5cc541 Author: Po Lu Date: Sat Aug 12 09:06:52 2023 +0800 * lisp/indent-aux.el (kill-ring-deindent-mode): Add autoload cookie. diff --git a/lisp/indent-aux.el b/lisp/indent-aux.el index 202e426c667..ed41d4926f7 100644 --- a/lisp/indent-aux.el +++ b/lisp/indent-aux.el @@ -54,6 +54,7 @@ kill-ring-deindent-buffer-substring-function (- indentation)) (buffer-string)))) +;;;###autoload (define-minor-mode kill-ring-deindent-mode "Toggle removal of indentation from text saved to the kill ring. commit 536b8b7bfd87a92aef9b78c62210e9f40c91e572 Author: Po Lu Date: Sat Aug 12 09:04:19 2023 +0800 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. 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 @@ analyze-text-conversion (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 commit 28ae8440c62c71da2ef7e30c73333bc5a51efba6 Author: Dmitry Gutov Date: Sat Aug 12 03:58:53 2023 +0300 Unbreak project-find-file's future history when cpd is not root * lisp/progmodes/project.el (project-find-file): Pass in buffer-file-name as absolute name (bug#63829). (project--read-file-cpd-relative): Make it relative to the appropriate common parent dir. diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 24531d9d02e..fe13f4ab114 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1005,7 +1005,7 @@ project-find-file (dirs (list root))) (project-find-file-in (or (thing-at-point 'filename) - (and buffer-file-name (file-relative-name buffer-file-name root))) + buffer-file-name) dirs pr include-all))) ;;;###autoload @@ -1058,6 +1058,11 @@ project--read-file-cpd-relative (setq all-files (delete common-parent-directory all-files)) t)) + (mb-default (if (and common-parent-directory + mb-default + (file-name-absolute-p mb-default)) + (file-relative-name mb-default common-parent-directory) + mb-default)) (substrings (mapcar (lambda (s) (substring s cpd-length)) all-files)) (_ (when included-cpd (setq substrings (cons "./" substrings)))) commit 0bd58dd2d605d5237483960c283e9e24706894e4 Author: Dmitry Gutov Date: Sat Aug 12 03:39:32 2023 +0300 xref-find-references-and-replace: Use identifier-at-point in prompt * lisp/progmodes/xref.el (xref-find-references-and-replace): Use identifier-at-point in prompt as defined by backend (bug#63939). diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index 643eea1b0a3..3f75f8d7132 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -1613,7 +1613,8 @@ xref-find-references (defun xref-find-references-and-replace (from to) "Replace all references to identifier FROM with TO." (interactive - (let* ((query-replace-read-from-default 'find-tag-default) + (let* ((query-replace-read-from-default + (lambda () (xref-backend-identifier-at-point (xref-find-backend)))) (common (query-replace-read-args "Query replace identifier" nil))) (list (nth 0 common) (nth 1 common)))) commit de093d49f233efbacb6b7f717692deb89a4f059c Author: Dmitry Gutov Date: Sat Aug 12 03:34:53 2023 +0300 (project--keymap-prompt): Use help-key-binding face * lisp/progmodes/project.el (project--keymap-prompt): Use help-key-binding face and adjust the prompt to fit (bug#64799). diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 2c5b07ce750..24531d9d02e 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1828,9 +1828,13 @@ project--keymap-prompt (let ((key (if key (vector key) (where-is-internal cmd (list project-prefix-map) t)))) - (format "[%s] %s" - (propertize (key-description key) 'face 'bold) - label))) + (if (facep 'help-key-binding) + (format "%s %s" + (propertize (key-description key) 'face 'help-key-binding) + label) + (format "[%s] %s" + (propertize (key-description key) 'face 'bold) + label)))) project-switch-commands " ")) commit 4fa75771d17800651cab6f1e97bc7fbb1f3e874b Author: Eli Zaretskii Date: Fri Aug 11 15:03:48 2023 +0300 ; * lisp/files.el (delete-file): Add expand-file-name back. diff --git a/lisp/files.el b/lisp/files.el index 685eb5fc957..69c4a33cdeb 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -6374,7 +6374,8 @@ delete-file (null current-prefix-arg))) (if (and (file-directory-p filename) (not (file-symlink-p filename))) (signal 'file-error (list "Removing old name: is a directory" filename))) - (let* ((handler (find-file-name-handler filename 'delete-file))) + (let* ((filename (expand-file-name filename)) + (handler (find-file-name-handler filename 'delete-file))) (cond (handler (funcall handler 'delete-file filename trash)) ((and delete-by-moving-to-trash trash) (move-file-to-trash filename)) (t (delete-file-internal filename))))) commit 44e941faa199b90ae9229841f699cc1a3441378f Author: Eli Zaretskii Date: Fri Aug 11 14:52:12 2023 +0300 ; Improve documentation of a recent addition * lisp/simple.el (kill-ring-deindent-buffer-substring-function): Doc fix. diff --git a/lisp/simple.el b/lisp/simple.el index 604ab0541bf..561b1f7fbeb 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -11146,11 +11146,12 @@ analyze-text-conversion ;; killed text to remove leading indentation. (defun kill-ring-deindent-buffer-substring-function (beg end delete) - "Save the text within BEG and END to the kill ring. -Maybe delete it if DELETE is non-nil. + "Save the text within BEG and END to kill-ring, decreasing indentation. +Delete the saved text if DELETE is non-nil. -Before saving the text, indent it leftwards by the number of -columns at BEG." +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) commit 3dbf2edb3c6cd7068558f5c453681185f5a40682 Author: Po Lu Date: Fri Aug 11 16:08:16 2023 +0800 Improve kill-ring-deindent-mode * etc/NEWS: * lisp/simple.el (kill-ring-deindent-buffer-substring-function): (kill-ring-deindent-mode): Deindent by the column number at BEG in lieu of the indentation at BEG. diff --git a/etc/NEWS b/etc/NEWS index ffd9632dc05..0388cca97aa 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -148,8 +148,8 @@ right-aligned to is controlled by the new user option --- ** New global minor mode 'kill-ring-deindent-mode'. When enabled, text being saved to the kill ring will be de-indented by -the number of columns its first line is indented. For example, -saving the entire function call within: +the column number at its start. For example, saving the entire +function call within: foo () { diff --git a/lisp/simple.el b/lisp/simple.el index 61e3af07df2..604ab0541bf 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -11150,13 +11150,13 @@ kill-ring-deindent-buffer-substring-function Maybe delete it if DELETE is non-nil. Before saving the text, indent it leftwards by the number of -columns of indentation at BEG." +columns at BEG." (let ((a beg) (b end)) (setq beg (min a b) end (max a b))) (let ((indentation (save-excursion (goto-char beg) - (current-indentation))) + (current-column))) (text (if delete (delete-and-extract-region beg end) (buffer-substring beg end)))) @@ -11170,8 +11170,8 @@ 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 number of columns the line at -the start of the text being saved is in turn indented." +indented towards the left by the column number at the start of +that text." :global 't :group 'killing (if kill-ring-deindent-mode commit dcd551d6c852cfa321d5552e2dfe273609396b45 Author: Po Lu Date: Fri Aug 11 15:58:31 2023 +0800 New global minor mode `kill-ring-deindent-mode' * etc/NEWS: Announce the new minor mode. * lisp/simple.el (kill-ring-deindent-buffer-substring-function): New function. (kill-ring-deindent-mode): New minor mode, for trimming excess indentation from saved text. diff --git a/etc/NEWS b/etc/NEWS index 5c7cee3e63b..ffd9632dc05 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -145,6 +145,29 @@ right-aligned to is controlled by the new user option * Editing Changes in Emacs 30.1 +--- +** New global minor mode 'kill-ring-deindent-mode'. +When enabled, text being saved to the kill ring will be de-indented by +the number of columns its first line is indented. For example, +saving the entire function call within: + +foo () +{ + long_function_with_several_arguments (argument_1_compute (), + argument_2_compute (), + argument_3_compute ()); +} + +will save: + +long_function_with_several_arguments (argument_1_compute (), + argument_2_compute (), + argument_3_compute ()) + +to the kill ring, omitting the two columns of extra indentation that +would otherwise be present in the second and third lines of the +function call. + +++ ** Emacs now has better support for touchscreen devices. Many touch screen gestures are now implemented and translated into diff --git a/lisp/simple.el b/lisp/simple.el index e21976c30ee..61e3af07df2 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -11142,6 +11142,45 @@ analyze-text-conversion +;; 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 the kill ring. +Maybe delete it if DELETE is non-nil. + +Before saving the text, indent it leftwards by the number of +columns of indentation at BEG." + (let ((a beg) + (b end)) + (setq beg (min a b) + end (max a b))) + (let ((indentation (save-excursion (goto-char beg) + (current-indentation))) + (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 number of columns the line at +the start of the text being saved is in turn indented." + :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