bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#1948: [PATCH] Always save the actual expansion (bug#1948)


From: Alan Third
Subject: bug#1948: [PATCH] Always save the actual expansion (bug#1948)
Date: Tue, 1 Mar 2016 18:19:42 +0000
User-agent: Mutt/1.5.24 (2015-08-30)

lisp/dabbrev.el (dabbrev--substitute-expansion): Return EXPANSION after
any processing.
lisp/dabbrev.el (dabbrev-expand): Set EXPANSION to the return value of
DABBREV--SUBSTITUTE-EXPANSION.
test/automated/dabbrev-tests.el (dabbrev-expand-test): Test for bug#1948.
---
 lisp/dabbrev.el                 |  8 +++++---
 test/automated/dabbrev-tests.el | 42 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 3 deletions(-)
 create mode 100644 test/automated/dabbrev-tests.el

diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el
index 3557041..d9f36b1 100644
--- a/lisp/dabbrev.el
+++ b/lisp/dabbrev.el
@@ -546,8 +546,8 @@ dabbrev-expand
                (copy-marker dabbrev--last-expansion-location)))
       ;; Success: stick it in and return.
       (setq buffer-undo-list (cons orig-point buffer-undo-list))
-      (dabbrev--substitute-expansion old abbrev expansion
-                                    record-case-pattern)
+      (setq expansion (dabbrev--substitute-expansion old abbrev expansion
+                                                     record-case-pattern))
 
       ;; Save state for re-expand.
       (setq dabbrev--last-expansion expansion)
@@ -902,7 +902,9 @@ dabbrev--substitute-expansion
     ;; and (2) the replacement itself is all lower case.
     (dabbrev--safe-replace-match expansion
                                 (not use-case-replace)
-                                t)))
+                                t))
+  ;; Return the expansion actually used.
+  expansion)
 
 
 ;;;----------------------------------------------------------------
diff --git a/test/automated/dabbrev-tests.el b/test/automated/dabbrev-tests.el
new file mode 100644
index 0000000..9c7a838
--- /dev/null
+++ b/test/automated/dabbrev-tests.el
@@ -0,0 +1,42 @@
+;;; dabbrev-tests.el --- Test suite for dabbrev.
+
+;; Copyright (C) 2016 Free Software Foundation, Inc.
+
+;; Author: Alan Third <alan@idiocy.org>
+;; Keywords: dabbrev
+
+;; 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 <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'ert)
+(require 'dabbrev)
+
+(ert-deftest dabbrev-expand-test ()
+  "Test for bug#1948.
+When DABBREV-ELIMINATE-NEWLINES is non-nil (the default),
+repeated calls to DABBREV-EXPAND can result in the source of
+first expansion being replaced rather than the destination."
+  (with-temp-buffer
+   (insert "ab  x\na\nab  y")
+   (goto-char 8)
+   (save-window-excursion
+     (set-window-buffer nil (current-buffer))
+     ;; M-/ SPC M-/ M-/
+     (execute-kbd-macro "\257 \257\257"))
+   (should (string= (buffer-string) "ab  x\nab y\nab  y"))))
-- 

Hope I've put the test file in the right place.
-- 
Alan Third





reply via email to

[Prev in Thread] Current Thread [Next in Thread]