From: "Mattias Engdegård" <mattiase@acm.org>
To: Shinichi Sakata <shinichi.sakata@gmail.com>
Cc: 41740@debbugs.gnu.org
Subject: bug#41740: 26.1; completion-at-point fails in the Pascal mode
Date: Sun, 21 Jun 2020 21:19:16 +0200 [thread overview]
Message-ID: <1DE58DD4-A8A5-45B4-B372-7504634BA86D@acm.org> (raw)
In-Reply-To: <CAADOr52+b3kNZRLCoK5JnLyUHy95jfb=ZKJt6bw97NyCayoDKQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 287 bytes --]
Thanks for the report! It looks like pascal-mode didn't obey the rules for completion functions: they mustn't move point.
Would you try these patches? The first should fix your bug, and the second deals with an apparent bug in C-M-a in pascal-mode found when fixing the first one.
[-- Attachment #2: 0001-Preserve-point-in-pascal-mode-completion-bug-41740.patch --]
[-- Type: application/octet-stream, Size: 5970 bytes --]
From a3e9f2c67c2feacbb6941d37966c251f03f99b87 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Sun, 21 Jun 2020 21:04:30 +0200
Subject: [PATCH 1/2] 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.
---
lisp/progmodes/pascal.el | 51 +++++++++++++-------------
test/lisp/progmodes/pascal-tests.el | 55 +++++++++++++++++++++++++++++
2 files changed, 82 insertions(+), 24 deletions(-)
create mode 100644 test/lisp/progmodes/pascal-tests.el
diff --git a/lisp/progmodes/pascal.el b/lisp/progmodes/pascal.el
index 536a16dbb3..b0191c029b 100644
--- a/lisp/progmodes/pascal.el
+++ b/lisp/progmodes/pascal.el
@@ -1170,26 +1170,27 @@ pascal-get-completion-decl
(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 @@ pascal-completion
(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
diff --git a/test/lisp/progmodes/pascal-tests.el b/test/lisp/progmodes/pascal-tests.el
new file mode 100644
index 0000000000..10d6e0433d
--- /dev/null
+++ b/test/lisp/progmodes/pascal-tests.el
@@ -0,0 +1,55 @@
+;;; pascal-tests.el --- tests for pascal.el -*- lexical-binding: t -*-
+
+;; Copyright (C) 2020 Free Software Foundation, Inc.
+
+;; 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 <https://www.gnu.org/licenses/>.
+
+(require 'ert)
+(require 'pascal)
+
+(ert-deftest pascal-completion ()
+ ;; Bug#41740: completion functions must preserve point.
+ (let ((pascal-completion-cache nil))
+ (with-temp-buffer
+ (pascal-mode)
+ (insert "program test; var")
+ (let* ((point-before (point))
+ (completions (pascal-completion "var" nil 'metadata))
+ (point-after (point)))
+ (should (equal completions nil))
+ (should (equal point-before point-after)))))
+
+ (let ((pascal-completion-cache nil))
+ (with-temp-buffer
+ (pascal-mode)
+ (insert "program test; function f(x : i")
+ (let* ((point-before (point))
+ (completions (pascal-completion "i" nil 'metadata))
+ (point-after (point)))
+ (should (equal completions nil))
+ (should (equal point-before point-after)))))
+
+ (let ((pascal-completion-cache nil))
+ (with-temp-buffer
+ (pascal-mode)
+ (insert "program test; function f(x : integer) : real")
+ (let* ((point-before (point))
+ (completions (pascal-completion "real" nil 'metadata))
+ (point-after (point)))
+ (should (equal completions nil))
+ (should (equal point-before point-after))))))
+
+(provide 'pascal-tests)
--
2.21.1 (Apple Git-122.3)
[-- Attachment #3: 0002-Fix-spurious-error-in-beginning-of-defun-in-pascal-m.patch --]
[-- Type: application/octet-stream, Size: 1694 bytes --]
From 6f20bd6baef7bcc490abd81fd177427d86cd0458 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Sun, 21 Jun 2020 21:11:17 +0200
Subject: [PATCH 2/2] Fix spurious error in beginning-of-defun in pascal-mode
(bug#41740)
* lisp/progmodes/pascal.el (pascal-beg-of-defun):
Ignore errors in forward-sexp.
* test/lisp/progmodes/pascal-tests.el (pascal-beg-of-defun): New test.
---
lisp/progmodes/pascal.el | 2 +-
test/lisp/progmodes/pascal-tests.el | 8 ++++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/lisp/progmodes/pascal.el b/lisp/progmodes/pascal.el
index b0191c029b..fce059bafc 100644
--- a/lisp/progmodes/pascal.el
+++ b/lisp/progmodes/pascal.el
@@ -589,7 +589,7 @@ pascal-beg-of-defun
(interactive)
(catch 'found
(if (not (looking-at (concat "\\s \\|\\s)\\|" pascal-defun-re)))
- (forward-sexp 1))
+ (ignore-errors (forward-sexp 1)))
(let ((nest 0) (max -1) (func 0)
(reg (concat pascal-beg-block-re "\\|"
pascal-end-block-re "\\|"
diff --git a/test/lisp/progmodes/pascal-tests.el b/test/lisp/progmodes/pascal-tests.el
index 10d6e0433d..ed4c6fb03e 100644
--- a/test/lisp/progmodes/pascal-tests.el
+++ b/test/lisp/progmodes/pascal-tests.el
@@ -52,4 +52,12 @@ pascal-completion
(should (equal completions nil))
(should (equal point-before point-after))))))
+(ert-deftest pascal-beg-of-defun ()
+ (with-temp-buffer
+ (pascal-mode)
+ (insert "program test; procedure p(")
+ (forward-char -1)
+ (pascal-beg-of-defun)
+ (should (equal (point) 15))))
+
(provide 'pascal-tests)
--
2.21.1 (Apple Git-122.3)
[-- Attachment #4: Type: text/plain, Size: 2 bytes --]
next prev parent reply other threads:[~2020-06-21 19:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-06 17:46 bug#41740: 26.1; completion-at-point fails in the Pacal mode Shinichi Sakata
2020-06-06 19:05 ` Dmitry Gutov
2020-06-21 19:19 ` Mattias Engdegård [this message]
[not found] ` <CAADOr53g1kykcatpC0djKq7Ke5CrwQQCO4yUMv7nrsSv=J9rcg@mail.gmail.com>
2020-06-22 8:00 ` bug#41740: 26.1; completion-at-point fails in the Pascal mode Mattias Engdegård
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1DE58DD4-A8A5-45B4-B372-7504634BA86D@acm.org \
--to=mattiase@acm.org \
--cc=41740@debbugs.gnu.org \
--cc=shinichi.sakata@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).