[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 2db7526 4/4: Fix defining inverse abbrevs on previo
From: |
Noam Postavsky |
Subject: |
[Emacs-diffs] master 2db7526 4/4: Fix defining inverse abbrevs on previous words (Bug#36243) |
Date: |
Sat, 22 Jun 2019 19:27:28 -0400 (EDT) |
branch: master
commit 2db75262c7395483d1fa9a0c9d93dd3e4d534e1f
Author: Allen Li <address@hidden>
Commit: Noam Postavsky <address@hidden>
Fix defining inverse abbrevs on previous words (Bug#36243)
* lisp/abbrev.el (inverse-add-abbrev): Skip trailing nonword
characters when defining abbrev.
* test/lisp/abbrev-tests.el (abbrev-edit-save-to-file-test): Add
regression tests.
---
lisp/abbrev.el | 1 +
test/lisp/abbrev-tests.el | 28 ++++++++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/lisp/abbrev.el b/lisp/abbrev.el
index 3c88ec6..3d0a843 100644
--- a/lisp/abbrev.el
+++ b/lisp/abbrev.el
@@ -352,6 +352,7 @@ Expands the abbreviation after defining it."
(let (name exp start end)
(save-excursion
(forward-word (1+ (- arg)))
+ (skip-syntax-backward "^w")
(setq end (point))
(backward-word 1)
(setq start (point)
diff --git a/test/lisp/abbrev-tests.el b/test/lisp/abbrev-tests.el
index 3b8acf5..2750e9a 100644
--- a/test/lisp/abbrev-tests.el
+++ b/test/lisp/abbrev-tests.el
@@ -274,6 +274,34 @@
(abbrev-expansion "s-a-t" ert-save-test-table)))
(delete-file temp-test-file))))
+(ert-deftest inverse-add-abbrev-skips-trailing-nonword ()
+ "Test that adding an inverse abbrev skips trailing nonword characters."
+ (let ((table (make-abbrev-table)))
+ (with-temp-buffer
+ (insert "some text foo ")
+ (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "bar")))
+ (inverse-add-abbrev table "Global" 1)))
+ (should (string= (abbrev-expansion "foo" table) "bar"))))
+
+(ert-deftest inverse-add-abbrev-skips-trailing-nonword/postiive-arg ()
+ "Test that adding an inverse abbrev skips trailing nonword characters."
+ (let ((table (make-abbrev-table)))
+ (with-temp-buffer
+ (insert "some text foo ")
+ (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "bar")))
+ (inverse-add-abbrev table "Global" 2)))
+ (should (string= (abbrev-expansion "text" table) "bar"))))
+
+(ert-deftest inverse-add-abbrev-skips-trailing-nonword/negative-arg ()
+ "Test that adding an inverse abbrev skips trailing nonword characters."
+ (let ((table (make-abbrev-table)))
+ (with-temp-buffer
+ (insert "some text foo")
+ (goto-char (point-min))
+ (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "bar")))
+ (inverse-add-abbrev table "Global" -1)))
+ (should (string= (abbrev-expansion "text" table) "bar"))))
+
(provide 'abbrev-tests)
;;; abbrev-tests.el ends here