* [PATCH] Implement texinfo @ref dwim
@ 2019-02-05 12:10 Robert Pluim
2019-02-05 16:31 ` Eli Zaretskii
0 siblings, 1 reply; 5+ messages in thread
From: Robert Pluim @ 2019-02-05 12:10 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 233 bytes --]
This has been sitting around in my patch queue for a while, and Iʼd
like to get it in so I can also get the manual update into the texinfo
project. I think Iʼve addressed all the comments from the last time
around.
Robert
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-dwim-function-for-inserting-ref-variants.patch --]
[-- Type: text/x-patch, Size: 3254 bytes --]
From 808733302749552e7928af4e6125b026b5db1ddd Mon Sep 17 00:00:00 2001
From: Robert Pluim <rpluim@gmail.com>
Date: Tue, 5 Feb 2019 10:49:09 +0100
Subject: [PATCH] Add dwim function for inserting @ref variants
To: emacs-devel@gnu.org
* lisp/textmodes/texinfo.el (texinfo-insert-dwim-@ref): New function.
Insert @ref variant based on surrounding context.
(texinfo-mode-map): Add binding for texinfo-insert-dwim-@ref.
* etc/NEWS: Describe new texinfo dwim reference functionality.
---
etc/NEWS | 8 ++++++++
lisp/textmodes/texinfo.el | 32 ++++++++++++++++++++++++++++++++
2 files changed, 40 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index 9bbe6befcf..d6f0232732 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -472,6 +472,14 @@ To enable it, set the new defcustom 'diff-font-lock-prettify' to t.
of the file under version control if point is on an old changed line,
or to the new revision of the file otherwise.
+** 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.
diff --git a/lisp/textmodes/texinfo.el b/lisp/textmodes/texinfo.el
index 1a900122f9..67a4081708 100644
--- a/lisp/textmodes/texinfo.el
+++ b/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,37 @@ 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 `@ref{}' 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
+ ((eq (char-before) ?\()
+ "@pxref{")
+ ;; beginning of sentence
+ ((looking-back (sentence-end) (point-at-bol 0))
+ "@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.
--
2.20.1.142.g77556354bb
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Implement texinfo @ref dwim
2019-02-05 12:10 [PATCH] Implement texinfo @ref dwim Robert Pluim
@ 2019-02-05 16:31 ` Eli Zaretskii
2019-02-05 19:42 ` Robert Pluim
0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2019-02-05 16:31 UTC (permalink / raw)
To: Robert Pluim; +Cc: emacs-devel
> From: Robert Pluim <rpluim@gmail.com>
> Date: Tue, 05 Feb 2019 13:10:07 +0100
>
> This has been sitting around in my patch queue for a while, and Iʼd
> like to get it in so I can also get the manual update into the texinfo
> project. I think Iʼve addressed all the comments from the last time
> around.
Thanks, I think this command will be useful.
> * etc/NEWS: Describe new texinfo dwim reference functionality.
I understand that the corresponding update to the Texinfo manual will
be submitted to the Texinfo maintainers? If so, the NEWS entry should
be marked with "+++", I think.
> +(define-skeleton texinfo-insert-dwim-@ref
> + "Insert appropriate `@pxref{...}', `@xref{}', or `@ref{}' command.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Is Emacs smart enough not to highlight these as links?
> + ;; parenthesis
> + ((eq (char-before) ?\()
> + "@pxref{")
@pxref is also good inside parentheses, not just after the opening
paren. Can this command be smarter and support also cases like
(bla-bla yak-yak @pxref{foo})
?
> + ;; beginning of sentence
> + ((looking-back (sentence-end) (point-at-bol 0))
> + "@xref{")
What about BOB? Can we produce @xref there as well?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Implement texinfo @ref dwim
2019-02-05 16:31 ` Eli Zaretskii
@ 2019-02-05 19:42 ` Robert Pluim
2019-02-06 16:09 ` Eli Zaretskii
0 siblings, 1 reply; 5+ messages in thread
From: Robert Pluim @ 2019-02-05 19:42 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1651 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Robert Pluim <rpluim@gmail.com>
>> Date: Tue, 05 Feb 2019 13:10:07 +0100
>>
>> This has been sitting around in my patch queue for a while, and Iʼd
>> like to get it in so I can also get the manual update into the texinfo
>> project. I think Iʼve addressed all the comments from the last time
>> around.
>
> Thanks, I think this command will be useful.
>
>> * etc/NEWS: Describe new texinfo dwim reference functionality.
>
> I understand that the corresponding update to the Texinfo manual will
> be submitted to the Texinfo maintainers? If so, the NEWS entry should
> be marked with "+++", I think.
>
Yes and yes.
>> +(define-skeleton texinfo-insert-dwim-@ref
>> + "Insert appropriate `@pxref{...}', `@xref{}', or `@ref{}' command.
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Is Emacs smart enough not to highlight these as links?
>
You mean in (describe-function 'texinfo-insert-dwim-@ref)? They show
up unadorned.
>> + ;; parenthesis
>> + ((eq (char-before) ?\()
>> + "@pxref{")
>
> @pxref is also good inside parentheses, not just after the opening
> paren. Can this command be smarter and support also cases like
>
> (bla-bla yak-yak @pxref{foo})
>
> ?
Yes, thatʼs possible. Iʼve limited the opening parenthesis to being on
the same or previous line though (I donʼt want excessive backwards
matching).
>> + ;; beginning of sentence
>> + ((looking-back (sentence-end) (point-at-bol 0))
>> + "@xref{")
>
> What about BOB? Can we produce @xref there as well?
Yes.
Revised version attached.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-dwim-function-for-inserting-ref-variants.patch --]
[-- Type: text/x-patch, Size: 3381 bytes --]
From d38394e5d54fe1c7997634bb2ebd966a36a52f82 Mon Sep 17 00:00:00 2001
From: Robert Pluim <rpluim@gmail.com>
Date: Tue, 5 Feb 2019 20:38:39 +0100
Subject: [PATCH] Add dwim function for inserting @ref variants
To: emacs-devel@gnu.org
* lisp/textmodes/texinfo.el (texinfo-insert-dwim-@ref): New function.
Insert @ref variant based on surrounding context.
(texinfo-mode-map): Add binding for texinfo-insert-dwim-@ref.
* etc/NEWS: Describe new texinfo dwim reference functionality.
---
etc/NEWS | 9 +++++++++
lisp/textmodes/texinfo.el | 33 +++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index 9bbe6befcf..5c06edd00a 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -472,6 +472,15 @@ To enable it, set the new defcustom 'diff-font-lock-prettify' to t.
of the file under version control if point is on an old changed line,
or to the new revision of the file otherwise.
+** 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 near a parenthesis, @xref at the
+start of a sentence or at (point-min), else @ref.
+
** Browse-url
*** The function 'browse-url-emacs' can now visit a URL in selected window.
diff --git a/lisp/textmodes/texinfo.el b/lisp/textmodes/texinfo.el
index 1a900122f9..71cdcab57e 100644
--- a/lisp/textmodes/texinfo.el
+++ b/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,38 @@ 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 `@ref{}' command.
+
+Looks at text around point to decide what to insert; an unclosed
+preceding open parenthesis results in '@pxref{}', point at the
+beginning of a sentence or at (point-min) 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 "([^)]*" (point-at-bol 0))
+ "@pxref{")
+ ;; beginning of sentence or buffer
+ ((or (looking-back (sentence-end) (point-at-bol 0))
+ (= (point) (point-min)))
+ "@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.
--
2.20.1.142.g77556354bb
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Implement texinfo @ref dwim
2019-02-05 19:42 ` Robert Pluim
@ 2019-02-06 16:09 ` Eli Zaretskii
2019-02-06 18:05 ` Robert Pluim
0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2019-02-06 16:09 UTC (permalink / raw)
To: Robert Pluim; +Cc: emacs-devel
> From: Robert Pluim <rpluim@gmail.com>
> Cc: emacs-devel@gnu.org
> Date: Tue, 05 Feb 2019 20:42:57 +0100
>
> Revised version attached.
LGTM, thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Implement texinfo @ref dwim
2019-02-06 16:09 ` Eli Zaretskii
@ 2019-02-06 18:05 ` Robert Pluim
0 siblings, 0 replies; 5+ messages in thread
From: Robert Pluim @ 2019-02-06 18:05 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: Tue, 05 Feb 2019 20:42:57 +0100
>>
>> Revised version attached.
>
> LGTM, thanks.
Thanks, pushed as 6ed9d0057d
Robert
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-02-06 18:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-05 12:10 [PATCH] Implement texinfo @ref dwim Robert Pluim
2019-02-05 16:31 ` Eli Zaretskii
2019-02-05 19:42 ` Robert Pluim
2019-02-06 16:09 ` Eli Zaretskii
2019-02-06 18:05 ` 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).