ptexinfmt.el (texinfo-format-syntax-table): Modify character syntax of " and \ to...
[elisp/wanderlust.git] / utils / ptexinfmt.el
index 741d9b3..e3d9d1b 100644 (file)
@@ -1,4 +1,4 @@
-;;; ptexinfmt.el -- portable Texinfo formatter.
+;;; ptexinfmt.el --- portable Texinfo formatter  -*- lexical-binding: t -*-
 
 ;; Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993,
 ;;               1994, 1995, 1996, 1997 Free Software Foundation, Inc.
 ;; Modified by Yamaoka not to use APEL functions.
 
 ;; Unimplemented command:
-;;  @abbr
-;;  @float, @caption, @shortcaption, @listoffloats
+;;  @abbr{ABBREVIATION}
+;;  @float ... @end float, @caption{TEXT}, @shortcaption{TEXT}, @listoffloats
 ;;  @deftypecv[x]
 ;;  @headitem
 ;;  @comma{}
 ;;  @quotation (optional arguments)
-;;  @acronym (optional argument)
+;;  @acronym{ACRONYM[, MEANING]} (optional argument)
 ;;  @dofirstparagraphindent
 ;;  @indent
-;;  @verbatiminclude
+;;  @verbatiminclude FILENAME
 ;;  @\
-;;  @definfoenclose
-;;  @deftypeivar
-;;  @deftypeop
-;;  @allowcodebreaks
+;;  @definfoenclose phoo,//,\\
+;;  @deftypeivar CLASS DATA-TYPE VARIABLE-NAME
+;;  @deftypeop CATEGORY CLASS DATA-TYPE NAME ARGUMENTS...
+;;  @allowcodebreaks false
 ;;  @thischapternum
 ;;  @quotedblleft @quotedblright
 ;;  @quoteleft @quoteright  @quotedblbase @quotesinglbase
 ;;  @guillemetleft @guillemetright @guilsinglleft @guilsinglright.
+;;  @clicksequence, @click, @clickstyle, @arrow
 
 ;;; Code:
 
 (require 'texinfmt)
 
+;; Work around a problem that double-quotes at bol disappear:
+;; @dfn{FOO} => FOO", ``BAR'' => BAR", \BAZ/ => BAZ/
+(modify-syntax-entry ?\" "w" texinfo-format-syntax-table)
+(modify-syntax-entry ?\\ "w" texinfo-format-syntax-table)
+
 ;;; Broken
 (defvar ptexinfmt-disable-broken-notice-flag t
   "If non-nil disable notice, when call `ptexinfmt-broken-facility'.
@@ -68,7 +74,7 @@ This is last argument in `ptexinfmt-broken-facility'.")
 
 (put 'ptexinfmt-broken-facility 'lisp-indent-function 'defun)
 (defmacro ptexinfmt-broken-facility (facility docstring assertion
-                                             &optional dummy)
+                                             &optional _dummy)
   "Declare a symbol FACILITY is broken if ASSERTION is nil.
 DOCSTRING will be printed if ASSERTION is nil and
 `ptexinfmt-disable-broken-notice-flag' is nil."
@@ -127,7 +133,9 @@ DOCSTRING will be printed if ASSERTION is nil and
       nil
     t))
 
-;; @var
+;; @var{METASYNTACTIC-VARIABLE}
+(defvar texinfo-enclosure-list)
+(defvar texinfo-alias-list)
 (ptexinfmt-broken-facility texinfo-format-var
   "Don't perse @var argument."
   (condition-case nil
@@ -139,7 +147,8 @@ DOCSTRING will be printed if ASSERTION is nil and
          t))
     (error nil)))
 
-;; @xref
+;; @xref{NODE-NAME[, CROSS-REFERENCE-NAME, TITLE-OR-TOPIC,
+;;     INFO-FILE-NAME, PRINTED-MANUAL-TITLE]}.
 (ptexinfmt-broken-facility texinfo-format-xref
   "Can't format @xref, 1st argument is empty."
   (condition-case nil
@@ -151,7 +160,7 @@ DOCSTRING will be printed if ASSERTION is nil and
          t))
     (error nil)))
 
-;; @uref
+;; @uref{URL[, TEXT][, REPLACEMENT]}
 (ptexinfmt-broken-facility texinfo-format-uref
   "Parse twice @uref argument."
   (condition-case nil
@@ -168,7 +177,10 @@ DOCSTRING will be printed if ASSERTION is nil and
   "`texinfo-multitable-widths' unsupport wide-char."
   (if (fboundp 'texinfo-multitable-widths)
       (with-temp-buffer
-       (let ((str "\e$BI}9-J8;z\e(B"))
+       (let ((str (string (make-char 'japanese-jisx0208 73 125)
+                          (make-char 'japanese-jisx0208 57 45)
+                          (make-char 'japanese-jisx0208 74 56)
+                          (make-char 'japanese-jisx0208 59 122))))
          (texinfo-mode)
          (insert (format " {%s}\n" str))
          (goto-char (point-min))
@@ -222,10 +234,10 @@ DOCSTRING will be printed if ASSERTION is nil and
 (put 'page 'texinfo-format 'texinfo-discard-line)
 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
 
-;; @slanted{} (makeinfo 4.8 or later)
+;; @slanted{TEXT} (makeinfo 4.8 or later)
 (put 'slanted 'texinfo-format 'texinfo-format-noop)
 
-;; @sansserif{} (makeinfo 4.8 or later)
+;; @sansserif{TEXT} (makeinfo 4.8 or later)
 (put 'sansserif 'texinfo-format 'texinfo-format-noop)
 
 ;; @tie{} (makeinfo 4.3 or later)
@@ -236,7 +248,7 @@ DOCSTRING will be printed if ASSERTION is nil and
 
 \f
 ;;; Directory File
-;; @direcategory
+;; @direcategory DIRPART
 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
 (ptexinfmt-defun-if-void texinfo-format-dircategory ()
   (let ((str (texinfo-parse-arg-discard)))
@@ -246,7 +258,7 @@ DOCSTRING will be printed if ASSERTION is nil and
                     (point)))
     (insert "INFO-DIR-SECTION " str "\n")))
 
-;; @direntry
+;; @direntry ... @end direntry
 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
 (ptexinfmt-defun-if-void texinfo-format-direntry ()
   (texinfo-push-stack 'direntry nil)
@@ -295,7 +307,6 @@ DOCSTRING will be printed if ASSERTION is nil and
 (put 'ifnotdocbook 'texinfo-format 'texinfo-discard-line)
 (put 'ifnotdocbook 'texinfo-end 'texinfo-discard-command)
 
-
 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo ()
@@ -338,25 +349,30 @@ DOCSTRING will be printed if ASSERTION is nil and
                 (progn (re-search-forward "@end ifdocbook[ \t]*\n")
                        (point))))
 
-
 \f
 ;;; Marking
-;; @indicateurl, @url, @env, @command, 
+;; @env{ENVIRONMENT-VARIABLE}
 (put 'env 'texinfo-format 'texinfo-format-code)
+
+;; @command{COMMAND-NAME}
 (put 'command 'texinfo-format 'texinfo-format-code)
 
+;; @indicateurl{INDICATEURL}
 (put 'indicateurl 'texinfo-format 'texinfo-format-code)
+
+;; @url{URL[, DISPLAYED-TEXT][, REPLACEMENT}
 (put 'url 'texinfo-format 'texinfo-format-uref)        ; Texinfo 4.7
 
-;; @acronym
+;; @acronym{ACRONYM}
 (put 'acronym 'texinfo-format 'texinfo-format-var)
 
+;; @var{METASYNTACTIC-VARIABLE}
 (ptexinfmt-defun-if-broken texinfo-format-var ()
   (let ((arg (texinfo-parse-expanded-arg)))
     (texinfo-discard-command)
     (insert (upcase arg))))
 
-;; @key
+;; @key{KEY-NAME}
 (put 'key 'texinfo-format 'texinfo-format-key)
 (ptexinfmt-defun-if-void texinfo-format-key ()
   (insert (texinfo-parse-arg-discard))
@@ -374,7 +390,7 @@ Insert < ... > around EMAIL-ADDRESS."
        (insert (nth 1 args) " <" (nth 0 args) ">")
       (insert "<" (nth 0 args) ">"))))
 
-;; @option
+;; @option{OPTION-NAME}
 (put 'option 'texinfo-format 'texinfo-format-option)
 (ptexinfmt-defun-if-void texinfo-format-option ()
   "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
@@ -403,18 +419,19 @@ For example, @verb\{|@|\} results in @ and
       (error "Not found: @verb start brace"))
     (delete-region texinfo-command-start (+ 2 texinfo-command-end))
     (search-forward  delimiter))
-  (delete-backward-char 1)
+  (delete-char -1)
   (unless (looking-at "}")
     (error "Not found: @verb end brace"))
   (delete-char 1))
 
 \f
-;;; @LaTeX, @registeredsymbol{}
+;; @LaTeX{}
 (put 'LaTeX 'texinfo-format 'texinfo-format-LaTeX)
 (ptexinfmt-defun-if-void texinfo-format-LaTeX ()
   (texinfo-parse-arg-discard)
   (insert "LaTeX"))
 
+;; @registeredsymbol{}
 (put 'registeredsymbol 'texinfo-format 'texinfo-format-registeredsymbol)
 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol ()
   (texinfo-parse-arg-discard)
@@ -605,15 +622,28 @@ For example, @verb\{|@|\} results in @ and
 (ptexinfmt-defun-if-void texinfo-format-\/ ()
   (texinfo-discard-command))
 
-;; @textdegree
+;; @textdegree{}
 (put 'textdegree 'texinfo-format 'texinfo-format-textdegree)
 (ptexinfmt-defun-if-void texinfo-format-textdegree ()
   (insert "o" (texinfo-parse-arg-discard))
   (goto-char texinfo-command-start))
 
+;; @geq{}
+(put 'geq 'texinfo-format 'texinfo-format-geq)
+(ptexinfmt-defun-if-void texinfo-format-geq ()
+  (insert ">=" (texinfo-parse-arg-discard))
+  (goto-char texinfo-command-start))
+
+;; @leq{}
+(put 'leq 'texinfo-format 'texinfo-format-leq)
+(ptexinfmt-defun-if-void texinfo-format-leq ()
+  (insert "<=" (texinfo-parse-arg-discard))
+  (goto-char texinfo-command-start))
+
 \f
 ;;; Cross References
-;; @ref, @xref
+;; @ref{NODE-NAME, ...}
+;; @xref{NODE-NAME, ...}
 (put 'ref 'texinfo-format 'texinfo-format-xref)
 
 (ptexinfmt-defun-if-broken texinfo-format-xref ()
@@ -642,7 +672,7 @@ otherwise, insert URL-TITLE followed by URL in parentheses."
        (insert  (nth 1 args) " (" (nth 0 args) ")")
       (insert "`" (nth 0 args) "'"))))
 
-;; @inforef
+;; @inforef{NODE-NAME, CROSS-REFERENCE-NAME, INFO-FILE-NAME}
 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
 (ptexinfmt-defun-if-void texinfo-format-inforef ()
   (let ((args (texinfo-format-parse-args)))
@@ -652,7 +682,7 @@ otherwise, insert URL-TITLE followed by URL in parentheses."
       (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
 
 
-;; @anchor
+;; @anchor{NAME}
 ;; don't emulation
 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
 ;;  - Info-tagify suport @anthor-*-refill.
@@ -962,6 +992,87 @@ This command is executed when texinfmt sees @item inside @multitable."
        (texinfo-sort-region opoint (point))
       (shell-command-on-region opoint (point) "sort -fd" 1))))
 
+\f
+;; @copying ... @end copying
+;; that Emacs 21.4 and lesser and XEmacs don't support.
+(if (fboundp 'texinfo-copying)
+    nil
+  (defvar texinfo-copying-text ""
+    "Text of the copyright notice and copying permissions.")
+
+  (defun texinfo-copying ()
+    "Copy the copyright notice and copying permissions from the Texinfo file,
+as indicated by the @copying ... @end copying command;
+insert the text with the @insertcopying command."
+    (let ((beg (progn (beginning-of-line) (point)))
+         (end  (progn (re-search-forward "^@end copying[ \t]*\n") (point))))
+      (setq texinfo-copying-text
+           (buffer-substring-no-properties
+            (save-excursion (goto-char beg) (forward-line 1) (point))
+            (save-excursion (goto-char end) (forward-line -1) (point))))
+      (delete-region beg end)))
+
+  (defun texinfo-insertcopying ()
+    "Insert the copyright notice and copying permissions from the Texinfo file,
+which are indicated by the @copying ... @end copying command."
+    (insert (concat "\n" texinfo-copying-text)))
+
+  (defadvice texinfo-format-scan (before expand-@copying-section activate)
+    "Extract @copying and replace @insertcopying with it."
+    (goto-char (point-min))
+    (when (search-forward "@copying" nil t)
+      (texinfo-copying))
+    (while (search-forward "@insertcopying" nil t)
+      (delete-region (match-beginning 0) (match-end 0))
+      (texinfo-insertcopying))))
+
+\f
+;; @comma
+(if (fboundp 'texinfo-format-comma)
+    nil
+  (put 'comma 'texinfo-format 'texinfo-format-comma)
+  (defun texinfo-format-comma ()
+    (texinfo-parse-arg-discard)
+    (insert ",")
+    (put-text-property (1- (point)) (point) 'ignore t))
+
+  ;; Redefine this function so as to work for @comma
+  (defun texinfo-format-parse-args ()
+    (let ((start (1- (point)))
+         next beg end
+         args)
+      (search-forward "{")
+      (save-excursion
+       (texinfo-format-expand-region
+        (point)
+        (save-excursion (up-list 1) (1- (point)))))
+      ;; The following does not handle cross references of the form:
+      ;; `@xref{bullet, , @code{@@bullet}@{@}}.' because the
+      ;; re-search-forward finds the first right brace after the second
+      ;; comma.
+      (while (/= (preceding-char) ?\})
+       (skip-chars-forward " \t\n")
+       (setq beg (point))
+;;;    (re-search-forward "[},]")
+       ;; Ignore commas that are derived from @comma{}.
+       (while (and (re-search-forward "[},]" nil t)
+                   (get-text-property (match-beginning 0) 'ignore)))
+;;;
+       (setq next (point))
+       (forward-char -1)
+       (skip-chars-backward " \t\n")
+       (setq end (point))
+       (cond ((< beg end)
+              (goto-char beg)
+              (while (search-forward "\n" end t)
+                (replace-match " "))))
+       (push (if (> end beg) (buffer-substring-no-properties beg end))
+             args)
+       (goto-char next))
+      ;;(if (eolp) (forward-char 1))
+      (setq texinfo-command-end (point))
+      (nreverse args))))
+
 (provide 'ptexinfmt)
 
 ;;; ptexinfmt.el ends here