summaryrefslogtreecommitdiff
path: root/lisp/textmodes/texinfo.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/textmodes/texinfo.el')
-rw-r--r--lisp/textmodes/texinfo.el38
1 files changed, 35 insertions, 3 deletions
diff --git a/lisp/textmodes/texinfo.el b/lisp/textmodes/texinfo.el
index f6aa8727410..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.")
(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)
@@ -596,9 +597,9 @@ value of `texinfo-mode-hook'."
(setq-local require-final-newline mode-require-final-newline)
(setq-local indent-tabs-mode nil)
(setq-local paragraph-separate
- (concat "\b\\|@[a-zA-Z]*[ \n]\\|"
+ (concat "@[a-zA-Z]*[ \n]\\|"
paragraph-separate))
- (setq-local paragraph-start (concat "\b\\|@[a-zA-Z]*[ \n]\\|"
+ (setq-local paragraph-start (concat "@[a-zA-Z]*[ \n]\\|"
paragraph-start))
(setq-local sentence-end-base "\\(@\\(end\\)?dots{}\\|[.?!]\\)[]\"'”)}]*")
(setq-local fill-column 70)
@@ -610,7 +611,6 @@ value of `texinfo-mode-hook'."
(setq font-lock-defaults
'(texinfo-font-lock-keywords nil nil nil backward-paragraph))
(setq-local syntax-propertize-function texinfo-syntax-propertize-function)
- (setq-local parse-sexp-lookup-properties t)
(setq-local add-log-current-defun-function #'texinfo-current-defun-name)
;; Outline settings.
@@ -826,6 +826,38 @@ Leave point after `@node'."
"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.