all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Aymeric Agon-Rambosson <aymeric.agon@yandex.com>,
	Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 67158@debbugs.gnu.org
Subject: bug#67158: [PATCH] Repair tab-always-indent
Date: Sat, 25 Nov 2023 11:31:36 +0200	[thread overview]
Message-ID: <835y1qdvrb.fsf@gnu.org> (raw)
In-Reply-To: <87msvhqkx6.fsf@X570GP> (message from Aymeric Agon-Rambosson on Tue, 14 Nov 2023 00:43:17 +0100)

> From: Aymeric Agon-Rambosson <aymeric.agon@yandex.com>
> Date: Tue, 14 Nov 2023 00:43:17 +0100
> 
> tab-first-completion does not work correctly at the moment, and 
> indent-for-tab-command must be modified in several ways to take 
> its meaning into account correctly :
> 
> Since syntax-after returns a list and not an integer, the forms 
> like (eql 2 syn) will always return nil. This was introduced by 
> commit c7234011518. We partially revert that commit, although it 
> would have been possible to solve this issue by wrapping 
> (syntax-after (point)) with syntax-class like so :

Stefan, any comments on these two patches?

> diff --git a/lisp/indent.el b/lisp/indent.el
> index 89de0a1d7d1..e5f2acdd33b 100644
> --- a/lisp/indent.el
> +++ b/lisp/indent.el
> @@ -171,7 +171,7 @@ prefix argument is ignored."
>      (let ((old-tick (buffer-chars-modified-tick))
>            (old-point (point))
>  	  (old-indent (current-indentation))
> -          (syn (syntax-after (point))))
> +          (syn (syntax-class (syntax-after (point)))))
>  
>        ;; Indent the line.
>        (or (not (eq (indent--funcall-widened indent-line-function) 'noindent))
> 
> Feel free to change the commit if you prefer this way.
> 
> Then, the semantic of word-or-paren and word-or-paren-or-punct is 
> not correctly implemented : in the current state, if 
> tab-first-completion is set to word-or-paren, and if 
> tab-always-indent is set to complete, and we press tab in the 
> middle of a word, the word will get autocompleted despite the 
> docstring promising the contrary because :
> 
> The following form will correctly return nil :
> 
> (and (memq tab-first-completion
>            '(word word-or-paren word-or-paren-or-punct))
>      (not (memq 2 syn)))
> 
> But this one will return non-nil :
> 
> (and (memq tab-first-completion
>            '(word-or-paren word-or-paren-or-punct))
>      (not (or (eql 4 syn)
>               (eql 5 syn))))
> 
> Since syn is equal to (2) (we are within a word).
> 
> The constraints need to be cumulative, since they are evaluated 
> until one succeeds. So we simply cumulate them so that 
> word-or-paren cannot succeed where word could not, and 
> word-or-paren-or-punct cannot succeed when word-or-paren could 
> not.
> 
> This is my first contribution with email. I have tried to follow 
> the guidelines specified in CONTRIBUTE and Sending-Patches. Feel 
> free to change the commit message or ask me to do it. I have 
> already attributed the Copyright to the FSF because of a previous 
> contribution.
>
> >From 8afb0f0ec8e645b41c8da2a5d5156e63fc04bdbd Mon Sep 17 00:00:00 2001
> From: Aymeric Agon-Rambosson <aymeric.agon@yandex.com>
> Date: Tue, 14 Nov 2023 00:03:46 +0100
> 
> Take the values word, word-or-paren, word-or-paren-or-punct correctly
> into account in the function indent-for-tab-command :
> * syntax-after returns a list, not an integer, either memq or member
> must be used (partial revert of c7234011518).
> * the constraints on completion-at-point must be cumulative when we go
> from word to word-or-paren to word-or-paren-or-punct. Otherwise, tab
> always complete with values word-or-paren or word-or-paren-or-punct,
> which is not what the docstring seems to say
> ---
>  lisp/indent.el | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/lisp/indent.el b/lisp/indent.el
> index 89de0a1d7d1..de8101dc76e 100644
> --- a/lisp/indent.el
> +++ b/lisp/indent.el
> @@ -191,13 +191,17 @@ prefix argument is ignored."
>                        (eolp))
>                   (and (memq tab-first-completion
>                              '(word word-or-paren word-or-paren-or-punct))
> -                      (not (eql 2 syn)))
> +                      (not (memq 2 syn)))
>                   (and (memq tab-first-completion
>                              '(word-or-paren word-or-paren-or-punct))
> -                      (not (or (eql 4 syn)
> -                               (eql 5 syn))))
> +                      (not (or (memq 2 syn)
> +                               (memq 4 syn)
> +                               (memq 5 syn))))
>                   (and (eq tab-first-completion 'word-or-paren-or-punct)
> -                      (not (eql 1 syn)))))
> +                      (not (or (memq 2 syn)
> +                               (memq 4 syn)
> +                               (memq 5 syn)
> +                               (memq 1 syn))))))
>          (completion-at-point))
>  
>         ;; If a prefix argument was given, rigidly indent the following
> -- 
> 2.39.2





  parent reply	other threads:[~2023-11-25  9:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-13 23:43 bug#67158: [PATCH] Repair tab-always-indent Aymeric Agon-Rambosson
2023-11-14 12:39 ` Eli Zaretskii
2023-11-15  0:24   ` Aymeric Agon-Rambosson
2023-11-25  9:31 ` Eli Zaretskii [this message]
2023-11-25 15:26 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-26  9:42   ` Aymeric Agon-Rambosson
2023-11-26 13:56     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-29 14:25       ` Eli Zaretskii

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=835y1qdvrb.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=67158@debbugs.gnu.org \
    --cc=aymeric.agon@yandex.com \
    --cc=monnier@iro.umontreal.ca \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.