unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: bug#31636: 27.0.50; lockfile syntax searchable from info manual
       [not found]                     ` <87y3fyskns.fsf@gmail.com>
@ 2018-06-01 13:42                       ` Robert Pluim
  2018-06-04  9:41                         ` Robert Pluim
  0 siblings, 1 reply; 15+ messages in thread
From: Robert Pluim @ 2018-06-01 13:42 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Robert Pluim <rpluim@gmail.com> writes:

> Eli Zaretskii <eliz@gnu.org> writes:
>
>>> (I noticed that texinfo.el has no bindings for inserting @ref,
>>> @xref, and @pxref, should I add some?  C-cC-c[rp] are free, but x is
>>> already used for @example, so 'C-cC-cX'? Or maybe 'C-cC-cC-x' for
>>> @xref?)
>>
>> How about using just "C-c C-c r" and letting it intuit the exact form
>> from the context?  @xref is only used at the beginning of a sentence,
>> and @pxref should normally follow an open paren.
>>
>
> OK. Iʼll think about how best to add that.
>

And of course had I implemented it, I wouldn't have made the silly
mistake in markup that I just fixed and pushed.

>> In any case, adding this to texinfo.el would be a welcome addition, I
>> think.

Yes.



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: bug#31636: 27.0.50; lockfile syntax searchable from info manual
  2018-06-01 13:42                       ` bug#31636: 27.0.50; lockfile syntax searchable from info manual Robert Pluim
@ 2018-06-04  9:41                         ` Robert Pluim
  2018-06-04 10:39                           ` Andreas Schwab
  2018-06-04 15:55                           ` Eli Zaretskii
  0 siblings, 2 replies; 15+ messages in thread
From: Robert Pluim @ 2018-06-04  9:41 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

>>>> (I noticed that texinfo.el has no bindings for inserting @ref,
>>>> @xref, and @pxref, should I add some?  C-cC-c[rp] are free, but x is
>>>> already used for @example, so 'C-cC-cX'? Or maybe 'C-cC-cC-x' for
>>>> @xref?)
>>>
>>> How about using just "C-c C-c r" and letting it intuit the exact form
>>> from the context?  @xref is only used at the beginning of a sentence,
>>> and @pxref should normally follow an open paren.
>>>
>>
>> OK. Iʼll think about how best to add that.

Hereʼs a simple implementation, no doubt Iʼve missed some corner cases.

diff --git i/lisp/textmodes/texinfo.el w/lisp/textmodes/texinfo.el
index c2ceee6e6b..b696b81c1c 100644
--- i/lisp/textmodes/texinfo.el
+++ w/lisp/textmodes/texinfo.el
@@ -470,6 +470,7 @@ texinfo-mode-map
     (define-key map "\C-c\C-cu"    'texinfo-insert-@uref)
     (define-key map "\C-c\C-ct"    'texinfo-insert-@table)
     (define-key map "\C-c\C-cs"    'texinfo-insert-@samp)
+    (define-key map "\C-c\C-cr"    'texinfo-insert-dwim-@ref)
     (define-key map "\C-c\C-cq"    'texinfo-insert-@quotation)
     (define-key map "\C-c\C-co"    'texinfo-insert-@noindent)
     (define-key map "\C-c\C-cn"    'texinfo-insert-@node)
@@ -826,6 +827,31 @@ texinfo-insert-@quotation
   "Insert the string `@quotation' in a Texinfo buffer."
   \n "@quotation" \n _ \n)
 
+(define-skeleton texinfo-insert-dwim-@ref
+  "Insert appropriate `@ref{...}', `@xref{}', or `@pxref{}' command
+in a Texinfo buffer depending on surrounding context.
+A numeric argument says how many words the braces should surround.
+The default is not to surround any existing words with the braces."
+  nil
+  (cond
+   ;; parenthetical
+   ((looking-back "\(")
+    "@pxref{")
+   ;; beginning of sentence
+   ((looking-back "  ")
+    "@xref{")
+   ;; bol or eol
+   ((looking-at "^\\|$")
+    "@ref{")
+   ;; inside word
+   ((not (eq (char-syntax (char-after)) ? ))
+    (skip-syntax-backward "^ ")
+    "@ref{")
+   ;; everything else
+   (t
+    "@ref{"))
+  _ "}")
+
 (define-skeleton texinfo-insert-@samp
   "Insert a `@samp{...}' command in a Texinfo buffer.
 A numeric argument says how many words the braces should surround.



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: bug#31636: 27.0.50; lockfile syntax searchable from info manual
  2018-06-04  9:41                         ` Robert Pluim
@ 2018-06-04 10:39                           ` Andreas Schwab
  2018-06-04 14:02                             ` Robert Pluim
  2018-06-04 15:55                           ` Eli Zaretskii
  1 sibling, 1 reply; 15+ messages in thread
From: Andreas Schwab @ 2018-06-04 10:39 UTC (permalink / raw)
  To: emacs-devel

On Jun 04 2018, Robert Pluim <rpluim@gmail.com> wrote:

> @@ -826,6 +827,31 @@ texinfo-insert-@quotation
>    "Insert the string `@quotation' in a Texinfo buffer."
>    \n "@quotation" \n _ \n)
>  
> +(define-skeleton texinfo-insert-dwim-@ref
> +  "Insert appropriate `@ref{...}', `@xref{}', or `@pxref{}' command

The first line should be one complete sentence.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: bug#31636: 27.0.50; lockfile syntax searchable from info manual
  2018-06-04 10:39                           ` Andreas Schwab
@ 2018-06-04 14:02                             ` Robert Pluim
  2018-06-04 16:06                               ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Robert Pluim @ 2018-06-04 14:02 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: emacs-devel

Andreas Schwab <schwab@suse.de> writes:

> On Jun 04 2018, Robert Pluim <rpluim@gmail.com> wrote:
>
>> @@ -826,6 +827,31 @@ texinfo-insert-@quotation
>>    "Insert the string `@quotation' in a Texinfo buffer."
>>    \n "@quotation" \n _ \n)
>>  
>> +(define-skeleton texinfo-insert-dwim-@ref
>> +  "Insert appropriate `@ref{...}', `@xref{}', or `@pxref{}' command
>
> The first line should be one complete sentence.

If thatʼs the only thing wrong with it, I guess itʼs a go.

Robert



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: bug#31636: 27.0.50; lockfile syntax searchable from info manual
  2018-06-04  9:41                         ` Robert Pluim
  2018-06-04 10:39                           ` Andreas Schwab
@ 2018-06-04 15:55                           ` Eli Zaretskii
  2018-06-04 17:17                             ` Robert Pluim
  1 sibling, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2018-06-04 15:55 UTC (permalink / raw)
  To: Robert Pluim; +Cc: emacs-devel

> From: Robert Pluim <rpluim@gmail.com>
> Cc: emacs-devel@gnu.org
> Date: Mon, 04 Jun 2018 11:41:24 +0200
> 
> +   ;; beginning of sentence
> +   ((looking-back "  ")
> +    "@xref{")

This misses the beginning of a sentence after a newline, right?

> +   ;; bol or eol
> +   ((looking-at "^\\|$")
> +    "@ref{")
> +   ;; inside word
> +   ((not (eq (char-syntax (char-after)) ? ))
> +    (skip-syntax-backward "^ ")
> +    "@ref{")
> +   ;; everything else
> +   (t
> +    "@ref{"))
> +  _ "}")

Why did you need the first 2 cases that yield @ref?

This will need a NEWS entry.

Thanks.



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: bug#31636: 27.0.50; lockfile syntax searchable from info manual
  2018-06-04 14:02                             ` Robert Pluim
@ 2018-06-04 16:06                               ` Eli Zaretskii
  0 siblings, 0 replies; 15+ messages in thread
From: Eli Zaretskii @ 2018-06-04 16:06 UTC (permalink / raw)
  To: Robert Pluim; +Cc: emacs-devel

> From: Robert Pluim <rpluim@gmail.com>
> Date: Mon, 04 Jun 2018 16:02:25 +0200
> Cc: emacs-devel@gnu.org
> 
> Andreas Schwab <schwab@suse.de> writes:
> 
> >> +(define-skeleton texinfo-insert-dwim-@ref
> >> +  "Insert appropriate `@ref{...}', `@xref{}', or `@pxref{}' command
> >
> > The first line should be one complete sentence.
> 
> If thatʼs the only thing wrong with it, I guess itʼs a go.

No, Andreas is just lightning-fast in responding.  It is usually a
good idea to leave a patch for a week at least before you decide there
are no more comments.

Thanks.



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: bug#31636: 27.0.50; lockfile syntax searchable from info manual
  2018-06-04 15:55                           ` Eli Zaretskii
@ 2018-06-04 17:17                             ` Robert Pluim
  2018-06-05 15:07                               ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Robert Pluim @ 2018-06-04 17:17 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Robert Pluim <rpluim@gmail.com>
>> Cc: emacs-devel@gnu.org
>> Date: Mon, 04 Jun 2018 11:41:24 +0200
>> 
>> +   ;; beginning of sentence
>> +   ((looking-back "  ")
>> +    "@xref{")
>
> This misses the beginning of a sentence after a newline, right?

Hmm. (looking-back (sentence-end)) perhaps? Or if thatʼs overkill
"\\(?:  \\|\\.\n\\)"

(I did wonder why thereʼs no (sentence-beginning))

>> +   ;; bol or eol
>> +   ((looking-at "^\\|$")
>> +    "@ref{")
>> +   ;; inside word
>> +   ((not (eq (char-syntax (char-after)) ? ))
>> +    (skip-syntax-backward "^ ")
>> +    "@ref{")
>> +   ;; everything else
>> +   (t
>> +    "@ref{"))
>> +  _ "}")
>
> Why did you need the first 2 cases that yield @ref?

If I have text like this:

word one
word two
 ^

with point where the ^ is, then we need to skip backwards until we
reach whitespace, otherwise we insert the ref in the middle of a word.

If we have this:

word one
word two
^

Then we donʼt want to skip backwards, since we'll end up before 'one',
hence we need to check for bol first. Similar reasoning applies for
eol.

I strongly suspect you'll now either ask for this to be explained in
the code and the docstring, or show me a single line of code that
achieves the same effect, thus providing me with another Emacs 'Aha!'
moment.

> This will need a NEWS entry.

Of course. Something like this, which will also go in the doc string.

** Texinfo
*** New function for inserting @pxref, @xref, or @ref commands
The function 'texinfo-insert-dwim-@ref', bound to 'C-c C-c r' by
default, inserts one of the three types of references based on the text
surrounding point, namely @pxref after a parenthesis, @xref at the
start of a sentence, else @ref.

Regards

Robert



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: bug#31636: 27.0.50; lockfile syntax searchable from info manual
  2018-06-04 17:17                             ` Robert Pluim
@ 2018-06-05 15:07                               ` Eli Zaretskii
  2018-06-05 19:51                                 ` Robert Pluim
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2018-06-05 15:07 UTC (permalink / raw)
  To: Robert Pluim; +Cc: emacs-devel

> From: Robert Pluim <rpluim@gmail.com>
> Cc: emacs-devel@gnu.org
> Date: Mon, 04 Jun 2018 19:17:16 +0200
> 
> >> +   ;; beginning of sentence
> >> +   ((looking-back "  ")
> >> +    "@xref{")
> >
> > This misses the beginning of a sentence after a newline, right?
> 
> Hmm. (looking-back (sentence-end)) perhaps? Or if thatʼs overkill
> "\\(?:  \\|\\.\n\\)"

sentence-end sounds fine to me.

> >> +   ;; bol or eol
> >> +   ((looking-at "^\\|$")
> >> +    "@ref{")
> >> +   ;; inside word
> >> +   ((not (eq (char-syntax (char-after)) ? ))
> >> +    (skip-syntax-backward "^ ")
> >> +    "@ref{")
> >> +   ;; everything else
> >> +   (t
> >> +    "@ref{"))
> >> +  _ "}")
> >
> > Why did you need the first 2 cases that yield @ref?
> 
> If I have text like this:

Sorry, I missed the skip-syntax-backward call.

> > This will need a NEWS entry.
> 
> Of course. Something like this, which will also go in the doc string.
> 
> ** Texinfo
> *** New function for inserting @pxref, @xref, or @ref commands

This should end with a period.

> The function 'texinfo-insert-dwim-@ref', bound to 'C-c C-c r' by
> default, inserts one of the three types of references based on the text
> surrounding point, namely @pxref after a parenthesis, @xref at the
> start of a sentence, else @ref.

OK.

Thanks.



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: bug#31636: 27.0.50; lockfile syntax searchable from info manual
  2018-06-05 15:07                               ` Eli Zaretskii
@ 2018-06-05 19:51                                 ` Robert Pluim
  2018-06-05 20:08                                   ` Noam Postavsky
  0 siblings, 1 reply; 15+ messages in thread
From: Robert Pluim @ 2018-06-05 19:51 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Latest version attached. I now limit the skip-syntax-backward to the
current line.

I have no idea how it was working correctly before, unless I somehow
managed to mess up the syntax table in my texinfo buffer (or more
likely I tested in a non-texinfo buffer). Testing appreciated.

((char-syntax (char-before)) at bol is '?>' in texinfo mode, which is
somewhat surprising, since it's '? ' in text mode)

Since the texinfo mode info documentation is part of the texinfo
package, Iʼll need to send them a patch as well.

2018-06-05  Robert Pluim  <rpluim@gmail.com>

	* lisp/textmodes/texinfo.el (texinfo-insert-dwim-@ref): New
	function. Insert appropriate type of reference based on
	surrounding text.
	(texinfo-mode-map): Add binding for texinfo-insert-dwim-@ref.

diff --git i/etc/NEWS w/etc/NEWS
index 01dcb441a7..a06bd442c2 100644
--- i/etc/NEWS
+++ w/etc/NEWS
@@ -171,6 +171,13 @@ interface that's more like functions like @code{search-forward}.
 \f
 * Changes in Specialized Modes and Packages in Emacs 27.1
 
+** Texinfo
+*** New function for inserting @pxref, @xref, or @ref commands.
+The function 'texinfo-insert-dwim-@ref', bound to 'C-c C-c r' by
+default, inserts one of three types of references based on the text
+surrounding point, namely @pxref after a parenthesis, @xref at the
+start of a sentence, else @ref.
+
 ** Browse-url
 *** The function 'browse-url-emacs' can now visit a URL in selected window.
 It now treats the optional 2nd argument to mean that the URL should be
diff --git i/lisp/textmodes/texinfo.el w/lisp/textmodes/texinfo.el
index ff723a4fb9..67333ddcf2 100644
--- i/lisp/textmodes/texinfo.el
+++ w/lisp/textmodes/texinfo.el
@@ -470,6 +470,7 @@ texinfo-mode-map
     (define-key map "\C-c\C-cu"    'texinfo-insert-@uref)
     (define-key map "\C-c\C-ct"    'texinfo-insert-@table)
     (define-key map "\C-c\C-cs"    'texinfo-insert-@samp)
+    (define-key map "\C-c\C-cr"    'texinfo-insert-dwim-@ref)
     (define-key map "\C-c\C-cq"    'texinfo-insert-@quotation)
     (define-key map "\C-c\C-co"    'texinfo-insert-@noindent)
     (define-key map "\C-c\C-cn"    'texinfo-insert-@node)
@@ -825,6 +826,36 @@ texinfo-insert-@quotation
   "Insert the string `@quotation' in a Texinfo buffer."
   \n "@quotation" \n _ \n)
 
+(define-skeleton texinfo-insert-dwim-@ref
+  "Insert appropriate `@pxref{...}', `@xref{}', or `@pef{}' command.
+Looks at text around point to decide what to insert; point after
+a parenthesis results in '@pxref{}', at the beginning of a
+sentence yields '@xref{}', any other location (including inside a
+word), will result in '@ref{}' at the nearest previous whitespace
+or beginning-of-line.
+A numeric argument says how many words the braces should
+surround.  The default is not to surround any existing words with
+the braces."
+  nil
+  (cond
+   ;; parenthesis
+   ((looking-back "\(")
+    "@pxref{")
+   ;; beginning of sentence
+   ((looking-back (sentence-end))
+    "@xref{")
+   ;; bol or eol
+   ((looking-at "^\\|$")
+    "@ref{")
+   ;; inside word
+   ((not (eq (char-syntax (char-after)) ? ))
+    (skip-syntax-backward "^ " (point-at-bol))
+    "@ref{")
+   ;; everything else
+   (t
+    "@ref{"))
+  _ "}")
+
 (define-skeleton texinfo-insert-@samp
   "Insert a `@samp{...}' command in a Texinfo buffer.
 A numeric argument says how many words the braces should surround.



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: bug#31636: 27.0.50; lockfile syntax searchable from info manual
  2018-06-05 19:51                                 ` Robert Pluim
@ 2018-06-05 20:08                                   ` Noam Postavsky
  2018-06-06  7:43                                     ` Robert Pluim
  0 siblings, 1 reply; 15+ messages in thread
From: Noam Postavsky @ 2018-06-05 20:08 UTC (permalink / raw)
  To: Emacs developers; +Cc: Eli Zaretskii

 On 5 June 2018 at 15:51, Robert Pluim <rpluim@gmail.com> wrote:
> Latest version attached. I now limit the skip-syntax-backward to the
> current line.

> ((char-syntax (char-before)) at bol is '?>' in texinfo mode, which is
> somewhat surprising, since it's '? ' in text mode)

This is the case in every mode which supports line comments, I think.

> +  (cond
> +   ;; parenthesis
> +   ((looking-back "\(")

That "\(" should be just "(". And I think you'll want to give a limit
to the looking-back calls, otherwise they can keep searching until the
beginning of buffer.



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: bug#31636: 27.0.50; lockfile syntax searchable from info manual
  2018-06-05 20:08                                   ` Noam Postavsky
@ 2018-06-06  7:43                                     ` Robert Pluim
  2018-06-06 13:13                                       ` Noam Postavsky
  0 siblings, 1 reply; 15+ messages in thread
From: Robert Pluim @ 2018-06-06  7:43 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: Eli Zaretskii, Emacs developers

Noam Postavsky <npostavs@gmail.com> writes:

>  On 5 June 2018 at 15:51, Robert Pluim <rpluim@gmail.com> wrote:
>> Latest version attached. I now limit the skip-syntax-backward to the
>> current line.
>
>> ((char-syntax (char-before)) at bol is '?>' in texinfo mode, which is
>> somewhat surprising, since it's '? ' in text mode)
>
> This is the case in every mode which supports line comments, I think.
>
>> +  (cond
>> +   ;; parenthesis
>> +   ((looking-back "\(")
>
> That "\(" should be just "(".

Overenthusiastic backslashitis strikes again.

> And I think you'll want to give a limit
> to the looking-back calls, otherwise they can keep searching until the
> beginning of buffer.

((looking-back "(") should never look at more than one character. I
could always do (eq (char-before) ?() I suppose.

The regexp produced by (sentence-end) looks like itʼs fairly well
anchored. Besides, Iʼm not searching for an end-of-sentence, Iʼm
asking "Am I at end-of-sentence".

Robert





^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: bug#31636: 27.0.50; lockfile syntax searchable from info manual
  2018-06-06  7:43                                     ` Robert Pluim
@ 2018-06-06 13:13                                       ` Noam Postavsky
  2018-06-06 13:51                                         ` Robert Pluim
  0 siblings, 1 reply; 15+ messages in thread
From: Noam Postavsky @ 2018-06-06 13:13 UTC (permalink / raw)
  To: Emacs developers; +Cc: Eli Zaretskii

On 6 June 2018 at 03:43, Robert Pluim <rpluim@gmail.com> wrote:

>> And I think you'll want to give a limit
>> to the looking-back calls, otherwise they can keep searching until the
>> beginning of buffer.
>
> ((looking-back "(") should never look at more than one character.

Perhaps it shouldn't, but Emacs doesn't make that kind of optimization:

(with-temp-buffer
  (let ((last-command-event ?a))
    (dotimes (i 8)
      (self-insert-command (expt 10 i))
      (benchmark 1 '(looking-back "(")))))
Elapsed time: 0.000036s
Elapsed time: 0.000030s
Elapsed time: 0.000066s
Elapsed time: 0.000427s
Elapsed time: 0.004068s
Elapsed time: 0.040317s
Elapsed time: 0.422173s
Elapsed time: 1.514244s

(with-temp-buffer
  (let ((last-command-event ?a))
    (dotimes (i 8)
      (self-insert-command (expt 10 i))
      (benchmark 1 '(looking-back "(" (1- (point)))))))
Elapsed time: 0.000031s
Elapsed time: 0.000027s [5 times]
Elapsed time: 0.000041s
Elapsed time: 0.000045s

> I could always do (eq (char-before) ?() I suppose.

That's probably better. But wait! This time you *should* have a backslash: ?\(

> The regexp produced by (sentence-end) looks like itʼs fairly well
> anchored. Besides, Iʼm not searching for an end-of-sentence, Iʼm
> asking "Am I at end-of-sentence".

Which is exactly why you should put a limit.



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: bug#31636: 27.0.50; lockfile syntax searchable from info manual
  2018-06-06 13:13                                       ` Noam Postavsky
@ 2018-06-06 13:51                                         ` Robert Pluim
  2018-06-06 14:41                                           ` Noam Postavsky
  0 siblings, 1 reply; 15+ messages in thread
From: Robert Pluim @ 2018-06-06 13:51 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: Eli Zaretskii, Emacs developers

Noam Postavsky <npostavs@gmail.com> writes:

> On 6 June 2018 at 03:43, Robert Pluim <rpluim@gmail.com> wrote:
>
>>> And I think you'll want to give a limit
>>> to the looking-back calls, otherwise they can keep searching until the
>>> beginning of buffer.
>>
>> ((looking-back "(") should never look at more than one character.
>
> Perhaps it shouldn't, but Emacs doesn't make that kind of optimization:
>
> (with-temp-buffer
>   (let ((last-command-event ?a))
>     (dotimes (i 8)
>       (self-insert-command (expt 10 i))
>       (benchmark 1 '(looking-back "(")))))
> Elapsed time: 0.000036s
> Elapsed time: 0.000030s
> Elapsed time: 0.000066s
> Elapsed time: 0.000427s
> Elapsed time: 0.004068s
> Elapsed time: 0.040317s
> Elapsed time: 0.422173s
> Elapsed time: 1.514244s
>
> (with-temp-buffer
>   (let ((last-command-event ?a))
>     (dotimes (i 8)
>       (self-insert-command (expt 10 i))
>       (benchmark 1 '(looking-back "(" (1- (point)))))))
> Elapsed time: 0.000031s
> Elapsed time: 0.000027s [5 times]
> Elapsed time: 0.000041s
> Elapsed time: 0.000045s
>
>> I could always do (eq (char-before) ?() I suppose.
>
> That's probably better. But wait! This time you *should* have a backslash: ?\(

Thatʼs a matter of style, no? ?( works equally well, but emacs
convention appears to be ?\(

>> The regexp produced by (sentence-end) looks like itʼs fairly well
>> anchored. Besides, Iʼm not searching for an end-of-sentence, Iʼm
>> asking "Am I at end-of-sentence".
>
> Which is exactly why you should put a limit.

I donʼt understand that conclusion. If I have

some words.  some other words
             ^

with point at '^', (looking-back (sentence-end)) will match. If point is
not at an end of sentence, looking-back won't go backwards through the
buffer attempting to find one.

Although I could limit it to (point-at-bol 0) just to be extra super
sure, but my benchmarking shows no appreciable difference.

Robert



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: bug#31636: 27.0.50; lockfile syntax searchable from info manual
  2018-06-06 13:51                                         ` Robert Pluim
@ 2018-06-06 14:41                                           ` Noam Postavsky
  2018-06-06 14:51                                             ` Robert Pluim
  0 siblings, 1 reply; 15+ messages in thread
From: Noam Postavsky @ 2018-06-06 14:41 UTC (permalink / raw)
  To: Emacs developers; +Cc: Eli Zaretskii

On 6 June 2018 at 09:51, Robert Pluim <rpluim@gmail.com> wrote:

>>> I could always do (eq (char-before) ?() I suppose.
>>
>> That's probably better. But wait! This time you *should* have a backslash: ?\(
>
> Thatʼs a matter of style, no? ?( works equally well, but emacs
> convention appears to be ?\(

Mostly yes, but see also Bug#20852.

>>> The regexp produced by (sentence-end) looks like itʼs fairly well
>>> anchored. Besides, Iʼm not searching for an end-of-sentence, Iʼm
>>> asking "Am I at end-of-sentence".
>>
>> Which is exactly why you should put a limit.
>
> I donʼt understand that conclusion. If I have
>
> some words.  some other words
>              ^
>
> with point at '^', (looking-back (sentence-end)) will match. If point is
> not at an end of sentence, looking-back won't go backwards through the
> buffer attempting to find one.

Even worse, it will go backwards through the buffer attempting to find
a sentence that ends at point.

(with-temp-buffer
  (dotimes (i 7)
    (dotimes (_ (expt 10 i))
      (insert "Lorem ipsum dolor sit amet, consectetur adipiscing
elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua.  Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat.  Duis
aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur.  Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit
anim id est laborum."))
    (insert "  Sentence doesn't end here")
    (benchmark 1 '(looking-back (sentence-end)))))
Elapsed time: 0.000000s [3 times]
Elapsed time: 0.023000s
Elapsed time: 0.101000s
Elapsed time: 0.902000s
Elapsed time: 8.872000s



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: bug#31636: 27.0.50; lockfile syntax searchable from info manual
  2018-06-06 14:41                                           ` Noam Postavsky
@ 2018-06-06 14:51                                             ` Robert Pluim
  0 siblings, 0 replies; 15+ messages in thread
From: Robert Pluim @ 2018-06-06 14:51 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: Eli Zaretskii, Emacs developers

Noam Postavsky <npostavs@gmail.com> writes:

> On 6 June 2018 at 09:51, Robert Pluim <rpluim@gmail.com> wrote:
>
>>>> I could always do (eq (char-before) ?() I suppose.
>>>
>>> That's probably better. But wait! This time you *should* have a backslash: ?\(
>>
>> Thatʼs a matter of style, no? ?( works equally well, but emacs
>> convention appears to be ?\(
>
> Mostly yes, but see also Bug#20852.
>

I see the documentation changed from 'should' to 'must' as a result of
that bug. ?\( it is.

> Even worse, it will go backwards through the buffer attempting to find
> a sentence that ends at point.
>
> (with-temp-buffer
>   (dotimes (i 7)
>     (dotimes (_ (expt 10 i))
>       (insert "Lorem ipsum dolor sit amet, consectetur adipiscing
> elit, sed do eiusmod tempor incididunt ut labore et dolore magna
> aliqua.  Ut enim ad minim veniam, quis nostrud exercitation
> ullamco laboris nisi ut aliquip ex ea commodo consequat.  Duis
> aute irure dolor in reprehenderit in voluptate velit esse cillum
> dolore eu fugiat nulla pariatur.  Excepteur sint occaecat
> cupidatat non proident, sunt in culpa qui officia deserunt mollit
> anim id est laborum."))
>     (insert "  Sentence doesn't end here")
>     (benchmark 1 '(looking-back (sentence-end)))))
> Elapsed time: 0.000000s [3 times]
> Elapsed time: 0.023000s
> Elapsed time: 0.101000s
> Elapsed time: 0.902000s
> Elapsed time: 8.872000s

OK. Looks like my mental model of 'looking-back' was wrong. Iʼll add
the limit.

Robert



^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2018-06-06 14:51 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20180529073311.EEA09102DA@mailuser.nyi.internal>
     [not found] ` <876036hn2e.fsf@gmail.com>
     [not found]   ` <87tvqqd7rp.fsf@gmail.com>
     [not found]     ` <87r2lufvo9.fsf@gmail.com>
     [not found]       ` <83r2luv28h.fsf@gnu.org>
     [not found]         ` <87a7sib7ty.fsf@gmail.com>
     [not found]           ` <83in75vp8l.fsf@gnu.org>
     [not found]             ` <87wovkyv6l.fsf@gmail.com>
     [not found]               ` <83tvqmga79.fsf@gnu.org>
     [not found]                 ` <87h8mmu6jp.fsf@gmail.com>
     [not found]                   ` <83k1rifyqo.fsf@gnu.org>
     [not found]                     ` <87y3fyskns.fsf@gmail.com>
2018-06-01 13:42                       ` bug#31636: 27.0.50; lockfile syntax searchable from info manual Robert Pluim
2018-06-04  9:41                         ` Robert Pluim
2018-06-04 10:39                           ` Andreas Schwab
2018-06-04 14:02                             ` Robert Pluim
2018-06-04 16:06                               ` Eli Zaretskii
2018-06-04 15:55                           ` Eli Zaretskii
2018-06-04 17:17                             ` Robert Pluim
2018-06-05 15:07                               ` Eli Zaretskii
2018-06-05 19:51                                 ` Robert Pluim
2018-06-05 20:08                                   ` Noam Postavsky
2018-06-06  7:43                                     ` Robert Pluim
2018-06-06 13:13                                       ` Noam Postavsky
2018-06-06 13:51                                         ` Robert Pluim
2018-06-06 14:41                                           ` Noam Postavsky
2018-06-06 14:51                                             ` Robert Pluim

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).