emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 6ed9d00: Add dwim function for inserting @ref varia


From: Robert Pluim
Subject: [Emacs-diffs] master 6ed9d00: Add dwim function for inserting @ref variants
Date: Wed, 6 Feb 2019 13:04:57 -0500 (EST)

branch: master
commit 6ed9d0057d9a8ef1331049c55d5df3cc4e02c5f2
Author: Robert Pluim <address@hidden>
Commit: Robert Pluim <address@hidden>

    Add dwim function for inserting @ref variants
    
    * 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                  |  9 +++++++++
 lisp/textmodes/texinfo.el | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 72a6b38..406ed6e 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -466,6 +466,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 '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 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 1a90012..71cdcab 100644
--- a/lisp/textmodes/texinfo.el
+++ b/lisp/textmodes/texinfo.el
@@ -470,6 +470,7 @@ Subexpression 1 is what goes into the corresponding 
address@hidden' statement.")
     (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,38 @@ Leave point after 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; 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 address@hidden
   "Insert a address@hidden' command in a Texinfo buffer.
 A numeric argument says how many words the braces should surround.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]