diff options
| author | Robert Pluim | 2019-02-05 20:38:39 +0100 |
|---|---|---|
| committer | Robert Pluim | 2019-02-06 18:59:01 +0100 |
| commit | 6ed9d0057d9a8ef1331049c55d5df3cc4e02c5f2 (patch) | |
| tree | 8c30af6678c85d2418c45240605ce99e2ea9a164 | |
| parent | 7fd2ad755e7fa599697648ac4c971e834de75bf3 (diff) | |
| download | emacs-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.
| -rw-r--r-- | etc/NEWS | 9 | ||||
| -rw-r--r-- | lisp/textmodes/texinfo.el | 33 |
2 files changed, 42 insertions, 0 deletions
| @@ -466,6 +466,15 @@ To enable it, set the new defcustom 'diff-font-lock-prettify' to t. | |||
| 466 | of the file under version control if point is on an old changed line, | 466 | of the file under version control if point is on an old changed line, |
| 467 | or to the new revision of the file otherwise. | 467 | or to the new revision of the file otherwise. |
| 468 | 468 | ||
| 469 | ** Texinfo | ||
| 470 | |||
| 471 | +++ | ||
| 472 | *** New function for inserting @pxref, @xref, or @ref commands. | ||
| 473 | The function 'texinfo-insert-dwim-@ref', bound to 'C-c C-c r' by | ||
| 474 | default, inserts one of three types of references based on the text | ||
| 475 | surrounding point, namely @pxref near a parenthesis, @xref at the | ||
| 476 | start of a sentence or at (point-min), else @ref. | ||
| 477 | |||
| 469 | ** Browse-url | 478 | ** Browse-url |
| 470 | 479 | ||
| 471 | *** The function 'browse-url-emacs' can now visit a URL in selected window. | 480 | *** 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 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 | |||
| 832 | Looks at text around point to decide what to insert; an unclosed | ||
| 833 | preceding open parenthesis results in '@pxref{}', point at the | ||
| 834 | beginning of a sentence or at (point-min) yields '@xref{}', any | ||
| 835 | other location (including inside a word), will result in '@ref{}' | ||
| 836 | at the nearest previous whitespace or beginning-of-line. A | ||
| 837 | numeric argument says how many words the braces should surround. | ||
| 838 | The default is not to surround any existing words with the | ||
| 839 | braces." | ||
| 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. |
| 830 | A numeric argument says how many words the braces should surround. | 863 | A numeric argument says how many words the braces should surround. |