aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/textmodes
diff options
context:
space:
mode:
authorRobert Pluim2019-02-05 20:38:39 +0100
committerRobert Pluim2019-02-06 18:59:01 +0100
commit6ed9d0057d9a8ef1331049c55d5df3cc4e02c5f2 (patch)
tree8c30af6678c85d2418c45240605ce99e2ea9a164 /lisp/textmodes
parent7fd2ad755e7fa599697648ac4c971e834de75bf3 (diff)
downloademacs-6ed9d0057d9a8ef1331049c55d5df3cc4e02c5f2.tar.gz
emacs-6ed9d0057d9a8ef1331049c55d5df3cc4e02c5f2.zip
Add dwim function for inserting @ref variants
* 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.
Diffstat (limited to 'lisp/textmodes')
-rw-r--r--lisp/textmodes/texinfo.el33
1 files changed, 33 insertions, 0 deletions
diff --git a/lisp/textmodes/texinfo.el b/lisp/textmodes/texinfo.el
index 1a900122f94..71cdcab57ef 100644
--- a/lisp/textmodes/texinfo.el
+++ b/lisp/textmodes/texinfo.el
@@ -470,6 +470,7 @@ Subexpression 1 is what goes into the corresponding `@end' statement.")
470 (define-key map "\C-c\C-cu" 'texinfo-insert-@uref) 470 (define-key map "\C-c\C-cu" 'texinfo-insert-@uref)
471 (define-key map "\C-c\C-ct" 'texinfo-insert-@table) 471 (define-key map "\C-c\C-ct" 'texinfo-insert-@table)
472 (define-key map "\C-c\C-cs" 'texinfo-insert-@samp) 472 (define-key map "\C-c\C-cs" 'texinfo-insert-@samp)
473 (define-key map "\C-c\C-cr" 'texinfo-insert-dwim-@ref)
473 (define-key map "\C-c\C-cq" 'texinfo-insert-@quotation) 474 (define-key map "\C-c\C-cq" 'texinfo-insert-@quotation)
474 (define-key map "\C-c\C-co" 'texinfo-insert-@noindent) 475 (define-key map "\C-c\C-co" 'texinfo-insert-@noindent)
475 (define-key map "\C-c\C-cn" 'texinfo-insert-@node) 476 (define-key map "\C-c\C-cn" 'texinfo-insert-@node)
@@ -825,6 +826,38 @@ Leave point after `@node'."
825 "Insert the string `@quotation' in a Texinfo buffer." 826 "Insert the string `@quotation' in a Texinfo buffer."
826 \n "@quotation" \n _ \n) 827 \n "@quotation" \n _ \n)
827 828
829(define-skeleton texinfo-insert-dwim-@ref
830 "Insert appropriate `@pxref{...}', `@xref{}', or `@ref{}' command.
831
832Looks at text around point to decide what to insert; an unclosed
833preceding open parenthesis results in '@pxref{}', point at the
834beginning of a sentence or at (point-min) yields '@xref{}', any
835other location (including inside a word), will result in '@ref{}'
836at the nearest previous whitespace or beginning-of-line. A
837numeric argument says how many words the braces should surround.
838The default is not to surround any existing words with the
839braces."
840 nil
841 (cond
842 ;; parenthesis
843 ((looking-back "([^)]*" (point-at-bol 0))
844 "@pxref{")
845 ;; beginning of sentence or buffer
846 ((or (looking-back (sentence-end) (point-at-bol 0))
847 (= (point) (point-min)))
848 "@xref{")
849 ;; bol or eol
850 ((looking-at "^\\|$")
851 "@ref{")
852 ;; inside word
853 ((not (eq (char-syntax (char-after)) ? ))
854 (skip-syntax-backward "^ " (point-at-bol))
855 "@ref{")
856 ;; everything else
857 (t
858 "@ref{"))
859 _ "}")
860
828(define-skeleton texinfo-insert-@samp 861(define-skeleton texinfo-insert-@samp
829 "Insert a `@samp{...}' command in a Texinfo buffer. 862 "Insert a `@samp{...}' command in a Texinfo buffer.
830A numeric argument says how many words the braces should surround. 863A numeric argument says how many words the braces should surround.