GNU bug report logs -
#31204
25.3; Make word motion more customizable
Previous Next
Reported by: Yuri Khan <yuri.v.khan <at> gmail.com>
Date: Wed, 18 Apr 2018 08:56:01 UTC
Severity: wishlist
Tags: moreinfo, wontfix
Found in version 25.3
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
Lars Ingebrigtsen <larsi <at> 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
This bug report was last modified 2 years and 343 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.