aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllen Li2019-06-16 03:32:02 -0700
committerNoam Postavsky2019-06-22 19:25:44 -0400
commit2db75262c7395483d1fa9a0c9d93dd3e4d534e1f (patch)
tree15e7327d356d20ddcc894810ecf3615fb1a22fe7
parent0f01a58c390faf30c33b369fc81b2a14ec5b7f2e (diff)
downloademacs-2db75262c7395483d1fa9a0c9d93dd3e4d534e1f.tar.gz
emacs-2db75262c7395483d1fa9a0c9d93dd3e4d534e1f.zip
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.
-rw-r--r--lisp/abbrev.el1
-rw-r--r--test/lisp/abbrev-tests.el28
2 files changed, 29 insertions, 0 deletions
diff --git a/lisp/abbrev.el b/lisp/abbrev.el
index 3c88ec661a9..3d0a843e375 100644
--- a/lisp/abbrev.el
+++ b/lisp/abbrev.el
@@ -352,6 +352,7 @@ Expands the abbreviation after defining it."
352 (let (name exp start end) 352 (let (name exp start end)
353 (save-excursion 353 (save-excursion
354 (forward-word (1+ (- arg))) 354 (forward-word (1+ (- arg)))
355 (skip-syntax-backward "^w")
355 (setq end (point)) 356 (setq end (point))
356 (backward-word 1) 357 (backward-word 1)
357 (setq start (point) 358 (setq start (point)
diff --git a/test/lisp/abbrev-tests.el b/test/lisp/abbrev-tests.el
index 3b8acf5519a..2750e9a6263 100644
--- a/test/lisp/abbrev-tests.el
+++ b/test/lisp/abbrev-tests.el
@@ -274,6 +274,34 @@
274 (abbrev-expansion "s-a-t" ert-save-test-table))) 274 (abbrev-expansion "s-a-t" ert-save-test-table)))
275 (delete-file temp-test-file)))) 275 (delete-file temp-test-file))))
276 276
277(ert-deftest inverse-add-abbrev-skips-trailing-nonword ()
278 "Test that adding an inverse abbrev skips trailing nonword characters."
279 (let ((table (make-abbrev-table)))
280 (with-temp-buffer
281 (insert "some text foo ")
282 (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "bar")))
283 (inverse-add-abbrev table "Global" 1)))
284 (should (string= (abbrev-expansion "foo" table) "bar"))))
285
286(ert-deftest inverse-add-abbrev-skips-trailing-nonword/postiive-arg ()
287 "Test that adding an inverse abbrev skips trailing nonword characters."
288 (let ((table (make-abbrev-table)))
289 (with-temp-buffer
290 (insert "some text foo ")
291 (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "bar")))
292 (inverse-add-abbrev table "Global" 2)))
293 (should (string= (abbrev-expansion "text" table) "bar"))))
294
295(ert-deftest inverse-add-abbrev-skips-trailing-nonword/negative-arg ()
296 "Test that adding an inverse abbrev skips trailing nonword characters."
297 (let ((table (make-abbrev-table)))
298 (with-temp-buffer
299 (insert "some text foo")
300 (goto-char (point-min))
301 (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "bar")))
302 (inverse-add-abbrev table "Global" -1)))
303 (should (string= (abbrev-expansion "text" table) "bar"))))
304
277(provide 'abbrev-tests) 305(provide 'abbrev-tests)
278 306
279;;; abbrev-tests.el ends here 307;;; abbrev-tests.el ends here