From: Lars Ingebrigtsen <larsi@gnus.org>
To: Yuri Khan <yuri.v.khan@gmail.com>
Cc: 31204@debbugs.gnu.org
Subject: bug#31204: 25.3; Make word motion more customizable
Date: Wed, 15 Jun 2022 17:03:16 +0200 [thread overview]
Message-ID: <87o7yugea3.fsf@gnus.org> (raw)
In-Reply-To: <875ym3dp41.fsf@gnus.org> (Lars Ingebrigtsen's message of "Wed, 18 May 2022 14:03:42 +0200")
Lars Ingebrigtsen <larsi@gnus.org> writes:
>> As an illustration (where ‘|’ specifies word motion stops when going
>> left to right):
>>
>> foo| ***| +++| (|bar|)|
[...]
> I think this sounds like it could be useful. If we added such a hook to
> `forward-word', what would the rest of the code look like to make
> `C-<right>' work this way?
I've played a bit at the patch below, but I tend to think that this is
going about things the wrong way. That is, for something like this to
work meaningfully, it would require a lot of setup (because
Vfind_word_boundary_function_table) would also have to be altered in
conjunction with this.
I.e., it's really about changing the definition of what a "word" is, and
in that case, I think it would be easier to just do that in a syntax
table, and then everything would work automatically.
(Or by advising the functions here.)
So I don't think it'd be worth it to proceed with something like the
below, and I'm therefore closing this bug report.
diff --git a/src/syntax.c b/src/syntax.c
index f9022d18d2..02d4dd4b9a 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -1462,20 +1462,33 @@ scan_words (ptrdiff_t from, EMACS_INT count)
while (count > 0)
{
- while (true)
+ if (!NILP (Vfind_word_start_function))
{
- if (from == end)
+ Lisp_Object np = call2 (Vfind_word_start_function,
+ make_fixnum (from), make_fixnum (end));
+ if (!FIXNUMP (np))
return 0;
- UPDATE_SYNTAX_TABLE_FORWARD (from);
+ from = XFIXNUM (np);
+ from_byte = CHAR_TO_BYTE (from);
ch0 = FETCH_CHAR_AS_MULTIBYTE (from_byte);
- code = SYNTAX (ch0);
- inc_both (&from, &from_byte);
- if (words_include_escapes
- && (code == Sescape || code == Scharquote))
- break;
- if (code == Sword)
- break;
- rarely_quit (from);
+ }
+ else
+ {
+ while (true)
+ {
+ if (from == end)
+ return 0;
+ UPDATE_SYNTAX_TABLE_FORWARD (from);
+ ch0 = FETCH_CHAR_AS_MULTIBYTE (from_byte);
+ code = SYNTAX (ch0);
+ inc_both (&from, &from_byte);
+ if (words_include_escapes
+ && (code == Sescape || code == Scharquote))
+ break;
+ if (code == Sword)
+ break;
+ rarely_quit (from);
+ }
}
/* Now CH0 is a character which begins a word and FROM is the
position of the next character. */
@@ -3792,6 +3805,12 @@ syms_of_syntax (void)
In both cases, LIMIT bounds the search. */);
Vfind_word_boundary_function_table = Fmake_char_table (Qnil, Qnil);
+ DEFVAR_LISP ("find-word-start-function",
+ Vfind_word_start_function,
+ doc: /* Function called to find the start of a word.
+It's called with two parameters, POS and LIMIT. */);
+ Vfind_word_start_function = Qnil;
+
DEFVAR_BOOL ("comment-end-can-be-escaped", comment_end_can_be_escaped,
doc: /* Non-nil means an escaped ender inside a comment doesn't end the comment. */);
comment_end_can_be_escaped = false;
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
prev parent reply other threads:[~2022-06-15 15:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-18 8:55 bug#31204: 25.3; Make word motion more customizable Yuri Khan
2022-05-18 12:03 ` Lars Ingebrigtsen
2022-06-15 15:03 ` Lars Ingebrigtsen [this message]
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=87o7yugea3.fsf@gnus.org \
--to=larsi@gnus.org \
--cc=31204@debbugs.gnu.org \
--cc=yuri.v.khan@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).