[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Implement texinfo @ref dwim
From: |
Robert Pluim |
Subject: |
[PATCH] Implement texinfo @ref dwim |
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.
Robert
>From 808733302749552e7928af4e6125b026b5db1ddd Mon Sep 17 00:00:00 2001
From: Robert Pluim <address@hidden>
Date: Tue, 5 Feb 2019 10:49:09 +0100
Subject: [PATCH] Add dwim function for inserting @ref variants
To: address@hidden
* lisp/textmodes/texinfo.el (address@hidden): New function.
Insert @ref variant based on surrounding context.
(texinfo-mode-map): Add binding for address@hidden
* 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 'address@hidden', 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" 'address@hidden)
(define-key map "\C-c\C-ct" 'address@hidden)
(define-key map "\C-c\C-cs" 'address@hidden)
+ (define-key map "\C-c\C-cr" 'address@hidden)
(define-key map "\C-c\C-cq" 'address@hidden)
(define-key map "\C-c\C-co" 'address@hidden)
(define-key map "\C-c\C-cn" 'address@hidden)
@@ -825,6 +826,37 @@ address@hidden
"Insert the string address@hidden' in a Texinfo buffer."
\n "@quotation" \n _ \n)
+(define-skeleton address@hidden
+ "Insert appropriate address@hidden', address@hidden', or address@hidden'
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 address@hidden
"Insert a address@hidden' command in a Texinfo buffer.
A numeric argument says how many words the braces should surround.
--
2.20.1.142.g77556354bb
- [PATCH] Implement texinfo @ref dwim,
Robert Pluim <=