1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Preserve point in pascal-mode completion (bug#41740)

Failure to do so caused errors in several cases.
Reported by Shinichi Sakata.

* lisp/progmodes/pascal.el (pascal-type-completion)
(pascal-completion): Wrap code that may move point in save-excursion.
* test/lisp/progmodes/pascal-tests.el: New file.
This commit is contained in:
Mattias Engdegård 2020-06-21 21:04:30 +02:00
parent ce4ec17930
commit 73daab9991
2 changed files with 82 additions and 24 deletions

View file

@ -1170,26 +1170,27 @@ indent of the current line in parameterlist."
(defun pascal-type-completion (pascal-str)
"Calculate all possible completions for types."
(let ((start (point))
(pascal-all ())
goon)
;; Search for all reachable type declarations
(while (or (pascal-beg-of-defun)
(setq goon (not goon)))
(save-excursion
(if (and (< start (prog1 (save-excursion (pascal-end-of-defun)
(point))
(forward-char 1)))
(re-search-forward
"\\<type\\>\\|\\<\\(begin\\|function\\|procedure\\)\\>"
start t)
(not (match-end 1)))
;; Check current type declaration
(setq pascal-all
(nconc (pascal-get-completion-decl pascal-str)
pascal-all)))))
(save-excursion
(let ((start (point))
(pascal-all ())
goon)
;; Search for all reachable type declarations
(while (or (pascal-beg-of-defun)
(setq goon (not goon)))
(save-excursion
(if (and (< start (prog1 (save-excursion (pascal-end-of-defun)
(point))
(forward-char 1)))
(re-search-forward
"\\<type\\>\\|\\<\\(begin\\|function\\|procedure\\)\\>"
start t)
(not (match-end 1)))
;; Check current type declaration
(setq pascal-all
(nconc (pascal-get-completion-decl pascal-str)
pascal-all)))))
pascal-all))
pascal-all)))
(defun pascal-var-completion (prefix)
"Calculate all possible completions for variables (or constants)."
@ -1263,11 +1264,13 @@ indent of the current line in parameterlist."
(and (eq state 'defun)
(save-excursion
(re-search-backward ")[ \t]*:" (point-at-bol) t))))
(if (or (eq state 'paramlist) (eq state 'defun))
(pascal-beg-of-defun))
(nconc
(pascal-type-completion pascal-str)
(pascal-keyword-completion pascal-type-keywords pascal-str)))
(save-excursion
(if (or (eq state 'paramlist) (eq state 'defun))
(pascal-beg-of-defun))
(nconc
(pascal-type-completion pascal-str)
(pascal-keyword-completion pascal-type-keywords
pascal-str))))
( ;--Starting a new statement
(and (not (eq state 'contexp))
(save-excursion