Sync to HEAD
[bpt/emacs.git] / lisp / textmodes / texinfo.el
index d578362..8e5b941 100644 (file)
@@ -1,10 +1,11 @@
 ;;; texinfo.el --- major mode for editing Texinfo files
 
-;; Copyright (C) 1985-2000 Free Software Foundation, Inc.
+;; Copyright (C) 1985,88,89,90,91,92,93,96,97,2000,01,03,04
+;;           Free Software Foundation, Inc.
 
 ;; Author: Robert J. Chassell
 ;; Date:   [See date below for texinfo-version]
-;; Maintainer: bug-texinfo@gnu.org
+;; Maintainer: FSF
 ;; Keywords: maint, tex, docs
 
 ;; This file is part of GNU Emacs.
 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 ;; Boston, MA 02111-1307, USA.
 
+;;; Todo:
+
+;; - facemenu support.
+;; - command completion.
+
+;;; Commentary:
+
 ;;; Code:
 
 (or (fboundp 'defgroup)
     (defmacro defcustom (var value doc &rest ignore)
       `(defvar ,var ,value ,doc)))
 
+(eval-when-compile (require 'tex-mode) (require 'cl))
+
 (defgroup texinfo nil
   "Texinfo Mode"
   :group 'docs)
 
+;;;###autoload
+(defcustom texinfo-open-quote "``"
+  "*String inserted by typing \\[texinfo-insert-quote] to open a quotation."
+  :type 'string
+  :group 'texinfo)
+
+;;;###autoload
+(defcustom texinfo-close-quote "''"
+  "*String inserted by typing \\[texinfo-insert-quote] to close a quotation."
+  :type 'string
+  :group 'texinfo)
+
+(defcustom texinfo-mode-hook nil
+  "Normal hook run when entering Texinfo mode."
+  :type 'hook
+  :options '(turn-on-auto-fill flyspell-mode)
+  :group 'texinfo)
+
 \f
 ;;; Autoloads:
 
@@ -78,15 +106,15 @@ marked region.
 The functions for creating or updating nodes and menus, and their
 keybindings, are:
 
-    texinfo-update-node (&optional region-p)    \\[texinfo-update-node]
-    texinfo-every-node-update ()                \\[texinfo-every-node-update]
-    texinfo-sequential-node-update (&optional region-p)
+    `texinfo-update-node' (&optional region-p)    \\[texinfo-update-node]
+    `texinfo-every-node-update' ()                \\[texinfo-every-node-update]
+    `texinfo-sequential-node-update' (&optional region-p)
 
-    texinfo-make-menu (&optional region-p)      \\[texinfo-make-menu]
-    texinfo-all-menus-update ()                 \\[texinfo-all-menus-update]
-    texinfo-master-menu ()
+    `texinfo-make-menu' (&optional region-p)      \\[texinfo-make-menu]
+    `texinfo-all-menus-update' ()                 \\[texinfo-all-menus-update]
+    `texinfo-master-menu' ()
 
-    texinfo-indent-menu-description (column &optional region-p)
+    `texinfo-indent-menu-description' (column &optional region-p)
 
 The `texinfo-column-for-description' variable specifies the column to
 which menu descriptions are indented. Its default value is 32."
@@ -244,22 +272,23 @@ chapter."
 
 (defvar texinfo-section-list
   '(("top" 1)
-    ("majorheading" 2)
     ("chapter" 2)
-    ("unnumbered" 2)
-    ("appendix" 2)
-    ("chapheading" 2)
     ("section" 3)
-    ("unnumberedsec" 3)
-    ("appendixsec" 3)
-    ("heading" 3)
     ("subsection" 4)
-    ("unnumberedsubsec" 4)
-    ("appendixsubsec" 4)
-    ("subheading" 4)
     ("subsubsection" 5)
+    ("unnumbered" 2)
+    ("unnumberedsec" 3)
+    ("unnumberedsubsec" 4)
     ("unnumberedsubsubsec" 5)
+    ("appendix" 2)
+    ("appendixsec" 3)
+    ("appendixsection" 3)
+    ("appendixsubsec" 4)
     ("appendixsubsubsec" 5)
+    ("majorheading" 2)
+    ("chapheading" 2)
+    ("heading" 3)
+    ("subheading" 4)
     ("subsubheading" 5))
   "Alist of sectioning commands and their relative level.")
 
@@ -270,8 +299,8 @@ chapter."
 (if texinfo-mode-syntax-table
     nil
   (setq texinfo-mode-syntax-table (make-syntax-table))
-  (modify-syntax-entry ?\" " " texinfo-mode-syntax-table)
-  (modify-syntax-entry ?\\ " " texinfo-mode-syntax-table)
+  (modify-syntax-entry ?\" "." texinfo-mode-syntax-table)
+  (modify-syntax-entry ?\\ "." texinfo-mode-syntax-table)
   (modify-syntax-entry ?@ "\\" texinfo-mode-syntax-table)
   (modify-syntax-entry ?\^q "\\" texinfo-mode-syntax-table)
   (modify-syntax-entry ?\[ "(]" texinfo-mode-syntax-table)
@@ -285,9 +314,9 @@ chapter."
 ;; To override this example, set either `imenu-generic-expression'
 ;; or `imenu-create-index-function'.
 (defvar texinfo-imenu-generic-expression
-  '((nil "^@node[ \t]+\\([^,\n]*\\)" 1)
+  '((nil "^@\\(node\\|anchor\\)[ \t]+\\([^,\n]*\\)" 2)
     ("Chapters" "^@chapter[ \t]+\\(.*\\)$" 1))
-  "Imenu generic expression for TexInfo mode.  See `imenu-generic-expression'.")
+  "Imenu generic expression for Texinfo mode.  See `imenu-generic-expression'.")
 
 (defvar texinfo-font-lock-syntactic-keywords
   '(("\\(@\\)c\\(omment\\)?\\>" (1 "<"))
@@ -295,6 +324,25 @@ chapter."
     ("^@end ignore\\(\n\\)" (1 "> b")))
   "Syntactic keywords to catch comment delimiters in `texinfo-mode'.")
 
+(defconst texinfo-environments
+  '("cartouche" "copying" "defcv" "deffn" "defivar" "defmac"
+    "defmethod" "defop" "defopt" "defspec" "deftp" "deftypefn"
+    "deftypefun" "deftypevar" "deftypevr" "defun" "defvar"
+    "defvr" "description" "detailmenu" "direntry" "display"
+    "documentdescription" "enumerate" "example" "flushleft"
+    "flushright" "format" "ftable" "group" "ifclear" "ifset"
+    "ifhtml" "ifinfo" "ifnothtml" "ifnotinfo" "ifnotplaintext"
+    "ifnottex" "ifplaintext" "iftex" "ignore" "itemize" "lisp"
+    "macro" "menu" "multitable" "quotation" "smalldisplay"
+    "smallexample" "smallformat" "smalllisp" "table" "tex"
+    "titlepage" "verbatim" "vtable")
+  "List of Texinfo environments.")
+
+(defconst texinfo-environment-regexp
+  (concat "^@" (regexp-opt (cons "end" texinfo-environments) t) "\\>")
+  "Regexp for environment-like Texinfo list commands.
+Subexpression 1 is what goes into the corresponding `@end' statement.")
+
 (defface texinfo-heading-face
   '((t (:inherit font-lock-function-name-face)))
   "Face used for section headings in `texinfo-mode'.")
@@ -306,29 +354,43 @@ chapter."
     ;; Robert J. Chassell <bob@gnu.org> says remove this line.
     ;;("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
     ("@\\([a-zA-Z]+\\|[^ \t\n]\\)" 1 font-lock-keyword-face) ;commands
-    ("^\\*\\(.*\\)[\t ]*$" 1 font-lock-function-name-face t) ;menu items
-    ("@\\(emph\\|strong\\|b\\|i\\|sc\\){\\([^}]+\\)" 2 font-lock-comment-face)
-    ("@\\(file\\|kbd\\|key\\|url\\|email\\){\\([^}]+\\)" 2 font-lock-string-face)
+    ("^\\*\\([^\n:]*\\)" 1 font-lock-function-name-face t) ;menu items
+    ("@\\(emph\\|i\\|sc\\){\\([^}]+\\)" 2 'italic)
+    ("@\\(strong\\|b\\){\\([^}]+\\)" 2 'bold)
+    ("@\\(kbd\\|key\\|url\\|uref\\){\\([^}]+\\)" 2 font-lock-string-face)
+    ;; The following two groups have an OVERRIDE of `keep' because
+    ;; their arguments frequently include a @@, and we don't want that
+    ;; to overwrite the normal fontification of the argument.
+    ("@\\(file\\|email\\){\\([^}]+\\)" 2 font-lock-string-face keep)
     ("@\\(samp\\|code\\|var\\|math\\|env\\|command\\|option\\){\\([^}]+\\)"
-     2 font-lock-variable-name-face)
-    ("@\\(cite\\|[ux]?ref\\|pxref\\){\\([^}]+\\)" 2 font-lock-constant-face)
-    ("@\\(end\\|itemx?\\) +\\(.+\\)" 2 font-lock-function-name-face keep)
+     2 font-lock-variable-name-face keep)
+    ("@\\(cite\\|x?ref\\|pxref\\|dfn\\|inforef\\){\\([^}]+\\)"
+     2 font-lock-constant-face)
+    ("@\\(anchor\\){\\([^}]+\\)" 2 font-lock-type-face)
+    ("@\\(dmn\\|acronym\\|value\\){\\([^}]+\\)" 2 font-lock-builtin-face)
+    ("@\\(end\\|itemx?\\) +\\(.+\\)" 2 font-lock-keyword-face keep)
+    ;; (,texinfo-environment-regexp
+    ;;  1 (texinfo-clone-environment (match-beginning 1) (match-end 1)) keep)
     (,(concat "^@" (regexp-opt (mapcar 'car texinfo-section-list) t)
-             ".*\n") 0 texinfo-heading-face t))
-  "Additional expressions to highlight in TeXinfo mode.")
+              ".*\n") 0 texinfo-heading-face t))
+  "Additional expressions to highlight in Texinfo mode.")
 
-(defun texinfo-outline-level ()
-  ;; Calculate level of current texinfo outline heading.
-  (save-excursion
-    (if (bobp)
-        0
-      (forward-char 1)
-      (let* ((word (buffer-substring-no-properties
-                    (point) (progn (forward-word 1) (point))))
-             (entry (assoc word texinfo-section-list)))
-        (if entry
-            (nth 1 entry)
-          5)))))
+(defun texinfo-clone-environment (start end)
+  (let ((endp nil))
+    (save-excursion
+      (ignore-errors
+       (goto-char start)
+       (when (looking-at "end\\Sw+\\(\\sw+\\)")
+         (setq endp t start (match-beginning 1) end (match-end 1)))
+       (unless (get-char-property start 'text-clones)
+         (if endp
+             (texinfo-last-unended-begin)
+           (forward-word 1)
+           (texinfo-next-unmatched-end))
+         (skip-syntax-forward "^w")
+         (when (looking-at
+                (concat (regexp-quote (buffer-substring start end)) "\\>"))
+           (text-clone-create start end 'spread "\\w*")))))))
 
 \f
 ;;; Keybindings
@@ -398,10 +460,9 @@ chapter."
   (define-key texinfo-mode-map "\C-c\C-c\C-e" 'texinfo-insert-@emph)
 
   (define-key texinfo-mode-map "\C-c\C-cv"    'texinfo-insert-@var)
-  (define-key texinfo-mode-map "\C-c\C-cu"    'texinfo-insert-@url)
+  (define-key texinfo-mode-map "\C-c\C-cu"    'texinfo-insert-@uref)
   (define-key texinfo-mode-map "\C-c\C-ct"    'texinfo-insert-@table)
   (define-key texinfo-mode-map "\C-c\C-cs"    'texinfo-insert-@samp)
-  ;; (define-key texinfo-mode-map "\C-c\C-cr"    'texinfo-insert-@uref)
   (define-key texinfo-mode-map "\C-c\C-cq"    'texinfo-insert-@quotation)
   (define-key texinfo-mode-map "\C-c\C-co"    'texinfo-insert-@noindent)
   (define-key texinfo-mode-map "\C-c\C-cn"    'texinfo-insert-@node)
@@ -436,6 +497,15 @@ chapter."
     ["Makeinfo buffer" makeinfo-buffer         t]))
 
 \f
+(defun texinfo-filter (section list)
+  (let (res)
+    (dolist (x list) (if (eq section (cadr x)) (push (car x) res)))
+    res))
+
+(defvar texinfo-chapter-level-regexp
+  (regexp-opt (texinfo-filter 2 texinfo-section-list))
+  "Regular expression matching just the Texinfo chapter level headings.")
+
 ;;; Texinfo mode
 
 ;;;###autoload
@@ -505,12 +575,11 @@ be the first node in the file.
 
 Entering Texinfo mode calls the value of `text-mode-hook', and then the
 value of `texinfo-mode-hook'."
-  (make-local-variable 'page-delimiter)
-  (setq page-delimiter
-        (concat
-         "^@node [ \t]*[Tt]op\\|^@\\("
-         "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
-         "\\)"))
+  (set (make-local-variable 'page-delimiter)
+       (concat
+       "^@node [ \t]*[Tt]op\\|^@\\("
+       texinfo-chapter-level-regexp
+       "\\)\\>"))
   (make-local-variable 'require-final-newline)
   (setq require-final-newline t)
   (make-local-variable 'indent-tabs-mode)
@@ -523,7 +592,7 @@ value of `texinfo-mode-hook'."
   (make-local-variable 'adaptive-fill-mode)
   (setq adaptive-fill-mode nil)
   (make-local-variable 'fill-column)
-  (setq fill-column 72)
+  (setq fill-column 70)
   (make-local-variable 'comment-start)
   (setq comment-start "@c ")
   (make-local-variable 'comment-start-skip)
@@ -535,15 +604,21 @@ value of `texinfo-mode-hook'."
   (setq imenu-case-fold-search nil)
   (make-local-variable 'font-lock-defaults)
   (setq font-lock-defaults
-       '(texinfo-font-lock-keywords nil nil nil nil
+       '(texinfo-font-lock-keywords nil nil nil backward-paragraph
                                     (font-lock-syntactic-keywords
                                      . texinfo-font-lock-syntactic-keywords)))
   (set (make-local-variable 'parse-sexp-lookup-properties) t)
-  (make-local-variable 'outline-regexp)
-  (setq outline-regexp
-        (concat "@" (regexp-opt (mapcar 'car texinfo-section-list) t) "\\>"))
-  (make-local-variable 'outline-level)
-  (setq outline-level 'texinfo-outline-level)
+
+  ;; Outline settings.
+  (set (make-local-variable 'outline-heading-alist)
+       ;; We should merge outline-heading-alist and texinfo-section-list
+       ;; but in the mean time, let's just generate one from the other.
+       (mapcar (lambda (x) (cons (concat "@" (car x)) (cadr x)))
+              texinfo-section-list))
+  (set (make-local-variable 'outline-regexp)
+       (concat (regexp-opt (mapcar 'car outline-heading-alist) t)
+              "\\>"))
+
   (make-local-variable 'tex-start-of-header)
   (setq tex-start-of-header "%\\*\\*start")
   (make-local-variable 'tex-end-of-header)
@@ -556,74 +631,15 @@ value of `texinfo-mode-hook'."
   ;; Prevent filling certain lines, in addition to ones specified
   ;; by the user.
   (let ((prevent-filling "^@\\(def\\|multitable\\)"))
-    (make-local-variable 'auto-fill-inhibit-regexp)
-    (if (null auto-fill-inhibit-regexp)
-       (setq auto-fill-inhibit-regexp prevent-filling)
-      (setq auto-fill-inhibit-regexp
-           (concat "\\(" auto-fill-inhibit-regexp "\\)\\|\\("
-                   prevent-filling "\\)")))))
-                 
+    (set (make-local-variable 'auto-fill-inhibit-regexp)
+        (if (null auto-fill-inhibit-regexp)
+            prevent-filling
+          (concat auto-fill-inhibit-regexp "\\|" prevent-filling)))))
+
 
 \f
 ;;; Insert string commands
 
-(defconst texinfo-environments
-  '("cartouche"
-    "defcv"
-    "deffn"
-    "defivar"
-    "defmac"
-    "defmethod"
-    "defop"
-    "defopt"
-    "defspec"
-    "deftp"
-    "deftypefn"
-    "deftypefun"
-    "deftypevar"
-    "deftypevr"
-    "defun"
-    "defvar"
-    "defvr"
-    "description"
-    "display"
-    "enumerate"
-    "example"
-    "flushleft"
-    "flushright"
-    "format"
-    "ftable"
-    "group"
-    "ifclear"
-    "ifset"
-    "ifhtml"
-    "ifinfo"
-    "ifnothtml"
-    "ifnotinfo"
-    "ifnottex"
-    "iftex"
-    "ignore"
-    "itemize"
-    "lisp"
-    "macro"
-    "multitable"
-    "quotation"
-    "smalldisplay"
-    "smallexample"
-    "smallformat"
-    "smalllisp"
-    "table"
-    "tex"
-    "titlepage"
-    "vtable")
-  "List of TeXinfo environments.")
-
-;; Keep as concatenated lists for ease of maintenance
-(defconst texinfo-environment-regexp
-  (concat "^@" (regexp-opt (cons "end" texinfo-environments) t) "\\>")
-  "Regexp for environment-like TexInfo list commands.
-   Subexpression 1 is what goes into the corresponding `@end' statement.")
-
 (defvar texinfo-block-default "example")
 
 (define-skeleton texinfo-insert-block
@@ -631,63 +647,85 @@ value of `texinfo-mode-hook'."
 Puts point on a blank line between them."
   (setq texinfo-block-default
        (completing-read (format "Block name [%s]: " texinfo-block-default)
-                        (mapcar 'list texinfo-environments)
+                        texinfo-environments
                         nil nil nil nil texinfo-block-default))
-  (unless (save-excursion (beginning-of-line) (looking-at "[ \t]*$")) '\n)
-  "@" str \n _ \n "@end " str \n)
+  \n "@" str \n _ \n "@end " str \n)
 
 (defun texinfo-inside-macro-p (macro &optional bound)
   "Non-nil if inside a macro matching the regexp MACRO."
-  (ignore-errors
-    (save-excursion
-      (save-restriction
-       (narrow-to-region bound (point))
-       (while (progn
-                (up-list -1)
-                (not (ignore-errors
-                       (save-excursion
-                         (backward-sexp 1)
-                         (looking-at macro))))))
-       t))))
+  (condition-case nil
+      (save-excursion
+       (save-restriction
+         (narrow-to-region bound (point))
+         (while (progn
+                  (up-list -1)
+                  (not (condition-case nil
+                           (save-excursion
+                             (backward-sexp 1)
+                             (looking-at macro))
+                         (scan-error nil)))))
+         t))
+    (scan-error nil)))
 
 (defun texinfo-inside-env-p (env &optional bound)
   "Non-nil if inside an environment matching the regexp @ENV."
   (save-excursion
     (and (re-search-backward (concat "@\\(end\\s +\\)?" env) bound t)
-        (looking-at (concat "@" env)))))
+        (not (match-end 1)))))
 
-(autoload 'tex-insert-quote "tex-mode" nil t)
+(defvar texinfo-enable-quote-macros "@\\(code\\|samp\\|kbd\\)\\>")
+(defvar texinfo-enable-quote-envs '("example\\>" "lisp\\>"))
 (defun texinfo-insert-quote (&optional arg)
-  "Insert the appropriate quote mark for TeXinfo.
-Inserts a plain \" if inside @code or @example, else inserts `` or ''
-by calling `tex-insert-quote'."
+  "Insert the appropriate quote mark for Texinfo.
+Usually inserts the value of `texinfo-open-quote' (normally ``) or
+`texinfo-close-quote' (normally ''), depending on the context.
+With prefix argument or inside @code or @example, inserts a plain \"."
   (interactive "*P")
   (let ((top (or (save-excursion (re-search-backward "@node\\>" nil t))
                 (point-min))))
-    (if (or (texinfo-inside-env-p "example\\>" top)
-           (texinfo-inside-macro-p "@code\\>" top))
+    (if (or arg
+           (= (preceding-char) ?\\)
+           (save-excursion
+             (backward-char (length texinfo-open-quote))
+             (when (or (looking-at texinfo-open-quote)
+                       (looking-at texinfo-close-quote))
+               (delete-char (length texinfo-open-quote))
+               t))
+           (texinfo-inside-macro-p texinfo-enable-quote-macros top)
+           (let ((in-env nil))
+             (dolist (env texinfo-enable-quote-envs in-env)
+               (if (texinfo-inside-env-p env top)
+                   (setq in-env t)))))
        (self-insert-command (prefix-numeric-value arg))
-      (tex-insert-quote arg))))
-       
+      (insert
+       (if (memq (char-syntax (preceding-char)) '(?\( ?> ?\ ))
+          texinfo-open-quote
+        texinfo-close-quote)))))
+
 ;; The following texinfo-insert-@end command not only inserts a SPC
 ;; after the @end, but tries to find out what belongs there.  It is
 ;; not very smart: it does not understand nested lists.
 
+(defun texinfo-last-unended-begin ()
+  (while (and (re-search-backward texinfo-environment-regexp)
+             (looking-at "@end"))
+    (texinfo-last-unended-begin)))
+
+(defun texinfo-next-unmatched-end ()
+  (while (and (re-search-forward texinfo-environment-regexp)
+             (save-excursion
+               (goto-char (match-beginning 0))
+               (not (looking-at "@end"))))
+    (texinfo-next-unmatched-end)))
+
 (defun texinfo-insert-@end ()
   "Insert the matching `@end' for the last Texinfo command that needs one."
   (interactive)
-  (let ((depth 1) string)
-    (save-excursion
-      (while (and (> depth 0)
-                  (re-search-backward texinfo-environment-regexp nil t))
-       (if (looking-at "@end")
-           (setq depth (1+ depth))
-         (setq depth (1- depth))))
-      (looking-at texinfo-environment-regexp)
-      (if (zerop depth)
-          (setq string
-                (buffer-substring (match-beginning 1)
-                                  (match-end 1)))))
+  (let ((string
+        (ignore-errors
+          (save-excursion
+            (texinfo-last-unended-begin)
+            (match-string 1)))))
     (insert "@end ")
     (if string (insert string "\n"))))
 
@@ -765,10 +803,18 @@ The default is not to surround any existing words with the braces."
   (texinfo-insert-@-with-arg "file" arg))
 
 (defun texinfo-insert-@item ()
-  "Insert the string `@item' in a Texinfo buffer."
+  "Insert the string `@item' in a Texinfo buffer.
+If in a table defined by @table, follow said string with a space.
+Otherwise, follow with a newline."
   (interactive)
-  (insert "@item")
-  (newline))
+  (insert "@item"
+         (if (equal (ignore-errors
+                     (save-excursion
+                       (texinfo-last-unended-begin)
+                       (match-string 1)))
+                    "table")
+             ? ;space
+           ?\n)))
 
 (defun texinfo-insert-@kbd (&optional arg)
   "Insert a `@kbd{...}' command in a Texinfo buffer.
@@ -779,11 +825,12 @@ The default is not to surround any existing words with the braces."
 
 (defun texinfo-insert-@node ()
   "Insert the string `@node' in a Texinfo buffer.
-This also inserts on the following line a comment indicating
-the order of arguments to @node."
+Insert a comment on the following line indicating the order of
+arguments to @node.  Insert a carriage return after the comment line.
+Leave point after `@node'."
   (interactive)
-  (insert "@node \n@comment  node-name,  next,  previous,  up")
-  (forward-line -1)
+  (insert "@node \n@comment  node-name,  next,  previous,  up\n")
+  (forward-line -2)
   (forward-char 6))
 
 (defun texinfo-insert-@noindent ()
@@ -810,9 +857,9 @@ The default is not to surround any existing words with the braces."
   (interactive "P")
   (texinfo-insert-@-with-arg "strong" arg))
 
-(defun texinfo-insert-@table (&optional arg)
+(defun texinfo-insert-@table ()
   "Insert the string `@table' in a Texinfo buffer."
-  (interactive "P")
+  (interactive)
   (insert "@table "))
 
 (defun texinfo-insert-@var (&optional arg)
@@ -822,12 +869,13 @@ The default is not to surround any existing words with the braces."
   (interactive "P")
   (texinfo-insert-@-with-arg "var" arg))
 
-(defun texinfo-insert-@url (&optional arg)
-  "Insert a `@url{}' command in a Texinfo buffer.
+(defun texinfo-insert-@uref (&optional arg)
+  "Insert a `@uref{}' command in a Texinfo buffer.
 A numeric argument says how many words the braces should surround.
 The default is not to surround any existing words with the braces."
   (interactive "P")
-  (texinfo-insert-@-with-arg "url" arg))
+  (texinfo-insert-@-with-arg "uref" arg))
+(defalias 'texinfo-insert-@url 'texinfo-insert-@uref)
 \f
 ;;; Texinfo file structure
 
@@ -842,28 +890,51 @@ with @-sign commands for @chapter, @section, and the like, and list
 
 Lines with structuring commands beginning in them are displayed in
 another buffer named `*Occur*'.  In that buffer, you can move point to
-one of those lines and then use \\<occur-mode-map>\\[occur-mode-goto-occurrence],
+one of those lines and then use
+\\<occur-mode-map>\\[occur-mode-goto-occurrence],
 to jump to the corresponding spot in the Texinfo source file."
 
   (interactive "P")
-  (save-excursion
+  ;; First, remember current location
+  (let (current-location)
+    (save-excursion
+      (end-of-line)            ; so as to find section on current line
+      (if (re-search-backward
+           ;; do not require `texinfo-section-types-regexp' in texnfo-upd.el
+           "^@\\(chapter \\|sect\\|subs\\|subh\\|unnum\\|major\\|chapheading \\|heading \\|appendix\\)"
+           nil t)
+          (setq current-location
+                (progn
+                  (beginning-of-line)
+                  (buffer-substring (point) (progn (end-of-line) (point)))))
+        ;; else point is located before any section command.
+        (setq current-location "tex")))
+    ;; Second, create and format an *Occur* buffer
+    (save-excursion
+      (goto-char (point-min))
+      (occur (concat "^\\(?:" (if nodes-too "@node\\>\\|")
+                    outline-regexp "\\)")))
+    (pop-to-buffer "*Occur*")
+    (goto-char (point-min))
+    (let ((inhibit-read-only t))
+      (flush-lines "-----")
+      ;; Now format the "*Occur*" buffer to show the structure.
+      ;; Thanks to ceder@signum.se (Per Cederqvist)
+      (goto-char (point-max))
+      (let (level)
+        (while (re-search-backward "^ *[0-9]*:@\\(\\sw+\\)" nil 0)
+          (goto-char (1- (match-beginning 1)))
+          (setq level
+                (or (cadr (assoc (match-string 1) texinfo-section-list)) 2))
+          (indent-to-column (+ (current-column) (* 4 (- level 2))))
+          (beginning-of-line))))
+    ;; Third, go to line corresponding to location in source file
+    ;; potential bug: two exactly similar `current-location' lines ...
     (goto-char (point-min))
-    (if nodes-too
-        (occur (concat "^@node\\>\\|" outline-regexp))
-      (occur outline-regexp)))
-  (pop-to-buffer "*Occur*")
-  (goto-char (point-min))
-  (let ((inhibit-read-only t))
-    (flush-lines "-----")
-    ;; Now format the "*Occur*" buffer to show the structure.
-    ;; Thanks to ceder@signum.se (Per Cederqvist)
-    (goto-char (point-max))
-    (let (level)
-      (while (re-search-backward "^ *[0-9]*:@\\(\\sw+\\)" nil 0)
-       (goto-char (1- (match-beginning 1)))
-       (setq level (or (cadr (assoc (match-string 1) texinfo-section-list)) 2))
-       (indent-to-column (+ (current-column) (* 4 (- level 2))))
-       (beginning-of-line)))))
+    (re-search-forward current-location nil t)
+    (beginning-of-line)
+    ))
+
 \f
 ;;; The  tex  and  print  function definitions:
 
@@ -981,4 +1052,5 @@ You are prompted for the job number (use a number shown by a previous
 
 (provide 'texinfo)
 
+;;; arch-tag: 005d7c38-43b9-4b7d-aa1d-aea69bae73e1
 ;;; texinfo.el ends here