mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-15 10:30:25 -08:00
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.
This commit is contained in:
parent
0f01a58c39
commit
2db75262c7
2 changed files with 29 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue