yuuji@13: ;;; -*- Emacs-Lisp -*-
yuuji@16: ;;; (c ) 1994 by HIROSE Yuuji [yuuji@ae.keio.ac.jp, pcs39334@ascii-net.or.jp]
yuuji@57: ;;; Last modified Mon Nov 20 11:26:38 1995 on inspire
yuuji@54: ;;; This is PURELY tentative.
yuuji@54: ;;; $Id$
yuuji@54:
yuuji@54: ;;;[Commentary]
yuuji@13: ;;;
yuuji@54: ;;; It is assumed you are already familiar with YaTeX. The following
yuuji@54: ;;; completing featureas are available: ([prefix] means `C-c' by default)
yuuji@54: ;;;
yuuji@54: ;;; * [prefix] b X Complete environments such as `H1' which
yuuji@57: ;;; normally requires closing tag `
yuuji@57: ;;; ... is also classified into
yuuji@57: ;;; this group
yuuji@54: ;;; * [prefix] s Complete declarative notations such as
yuuji@57: ;;; `'
yuuji@57: ;;; `'
yuuji@54: ;;; * [prefix] l Complete typeface-changing commands such as
yuuji@54: ;;; ` ... ' or ` ... '
yuuji@57: ;;; * [prefix] m Complete single commands such as
yuuji@57: ;;; `
' or `
\\|^[ \t]*?\\(h[1-6]\\|p\\|dl\\|dd\\|dt\\|li\\|body\\|html\\|head\\|title\\|ul\\|ol\\|dl\\|pre\\)>")
yuuji@57: "*Regexp of html paragraph separater")
yuuji@54: (defvar yahtml-syntax-table nil
yuuji@54: "*Syntax table for typesetting buffer")
yuuji@54:
yuuji@54: (if yahtml-syntax-table nil
yuuji@54: (setq yahtml-syntax-table
yuuji@54: (make-syntax-table (standard-syntax-table)))
yuuji@54: (modify-syntax-entry ?\< "(" yahtml-syntax-table)
yuuji@54: (modify-syntax-entry ?\> ")" yahtml-syntax-table)
yuuji@54: )
yuuji@54: (defvar yahtml-command-regexp "[A-Za-z0-9]+"
yuuji@54: "Regexp of constituent of html commands.")
yuuji@57: (defvar yahtml-kanji-code 2
yuuji@57: "Kanji coding system of html file; 1=sjis, 2=jis, 3=euc")
yuuji@54:
yuuji@54: ;;; Completion tables for `form'
yuuji@57: (defvar yahtml-form-table
yuuji@57: '(("img") ("input")))
yuuji@54: (defvar yahtml-user-form-table nil)
yuuji@54: (defvar yahtml-tmp-form-table nil)
yuuji@54:
yuuji@54: (defvar yahtml-env-table
yuuji@57: '(("html") ("head") ("title") ("body") ("dl") ("a") ("form") ("select")
yuuji@57: ("h1") ("h2") ("h3") ("h4") ("h5") ("h6") ("ul")))
yuuji@57:
yuuji@57: (defvar yahtml-user-env-table nil)
yuuji@57: (defvar yahtml-tmp-env-table nil)
yuuji@54:
yuuji@54: ;;; Completion tables for typeface designator
yuuji@54: (defvar yahtml-typeface-table
yuuji@54: '(("defn") ("em") ("cite") ("code") ("kbd") ("samp")
yuuji@57: ("strong") ("var") ("b") ("i") ("tt") ("u") ("address"))
yuuji@54: "Default completion table of typeface designator")
yuuji@54: (defvar yahtml-user-typeface-table nil)
yuuji@54: (defvar yahtml-tmp-typeface-table nil)
yuuji@54:
yuuji@57: (defvar yahtml-single-cmd-table
yuuji@57: '(("hr") ("br") ("option") ("p"))
yuuji@57: "Default completion table of HTML single command.")
yuuji@57: (defvar yahtml-user-single-cmd-table nil)
yuuji@57: (defvar yahtml-tmp-single-cmd-table nil)
yuuji@57: (defvar yahtml-last-single-cmd nil)
yuuji@57:
yuuji@54: (defvar yahtml-prefer-upcases nil)
yuuji@54: (cond
yuuji@54: (yahtml-prefer-upcases
yuuji@54: (setq yahtml-form-table
yuuji@54: (mapcar (function (lambda (list) (list (upcase (car list)))))
yuuji@54: yahtml-form-table))
yuuji@54: (setq yahtml-env-table
yuuji@54: (mapcar (function (lambda (list) (list (upcase (car list)))))
yuuji@54: yahtml-env-table))
yuuji@54: (setq yahtml-typeface-table
yuuji@54: (mapcar (function (lambda (list) (list (upcase (car list)))))
yuuji@54: yahtml-typeface-table))))
yuuji@13:
yuuji@57: (defvar yahtml-struct-name-regexp
yuuji@57: "\\<\\(h[1-6]\\|[uod]l\\|body\\|title\\|head\\)")
yuuji@57:
yuuji@57:
yuuji@13: (defun yahtml-mode ()
yuuji@13: (interactive)
yuuji@13: (yatex-mode)
yuuji@57: (cond
yuuji@57: ((boundp 'MULE)
yuuji@57: (set-file-coding-system
yuuji@57: (cdr (assq yahtml-kanji-code YaTeX-kanji-code-alist))))
yuuji@57: ((boundp 'NEMACS)
yuuji@57: (make-local-variable 'kanji-fileio-code)
yuuji@57: (setq kanji-fileio-code yahtml-kanji-code)))
yuuji@13: (setq major-mode 'yahtml-mode
yuuji@13: mode-name "yahtml")
yuuji@54: (make-local-variable 'YaTeX-ec) (setq YaTeX-ec "")
yuuji@57: (make-local-variable 'YaTeX-struct-begin) (setq YaTeX-struct-begin "<%1%2>")
yuuji@54: (make-local-variable 'YaTeX-struct-end) (setq YaTeX-struct-end "%1>")
yuuji@54: (make-local-variable 'YaTeX-struct-name-regexp)
yuuji@57: (setq YaTeX-struct-name-regexp yahtml-struct-name-regexp)
yuuji@13: (make-local-variable 'YaTeX-prefix-map)
yuuji@54: (make-local-variable 'YaTeX-command-token-regexp)
yuuji@54: (setq YaTeX-command-token-regexp yahtml-command-regexp)
yuuji@57: (make-local-variable 'YaTeX-environment-indent)
yuuji@57: (setq YaTeX-environment-indent 0)
yuuji@57: (make-local-variable 'fill-prefix)
yuuji@57: (setq fill-prefix nil)
yuuji@57: (make-local-variable 'paragraph-separate)
yuuji@57: (setq paragraph-separate yahtml-paragraph-separate
yuuji@57: paragraph-start yahtml-paragraph-separate)
yuuji@57: (make-local-variable 'comment-start)
yuuji@57: (make-local-variable 'comment-end)
yuuji@57: (setq comment-start "")
yuuji@54: (set-syntax-table yahtml-syntax-table)
yuuji@13: (use-local-map yahtml-mode-map)
yuuji@54: (run-hooks 'yahtml-mode-hook))
yuuji@54:
yuuji@54: (defun yahtml-define-menu (keymap bindlist)
yuuji@54: (mapcar
yuuji@54: (function
yuuji@54: (lambda (bind)
yuuji@54: (define-key keymap (vector (car bind)) (cdr bind))))
yuuji@54: bindlist))
yuuji@54:
yuuji@54: (defvar yahtml-menu-map nil "Menu map of yahtml")
yuuji@54: (defvar yahtml-menu-map-sectioning nil "Menu map of yahtml(sectioning)")
yuuji@54: (defvar yahtml-menu-map-listing nil "Menu map of yahtml(listing)")
yuuji@54: (defvar yahtml-menu-map-logical nil "Menu map of yahtml(logical tags)")
yuuji@54: (defvar yahtml-menu-map-typeface nil "Menu map of yahtml(typeface tags)")
yuuji@54:
yuuji@54: ;;; Variables for mosaic url history
yuuji@54: (defvar yahtml-urls nil "Alist of global history")
yuuji@54: (defvar yahtml-url-history-file "~/.mosaic-global-history"
yuuji@54: "File name of url history")
yuuji@54:
yuuji@54: (cond
yuuji@54: ((and YaTeX-emacs-19 (null yahtml-menu-map))
yuuji@54: (setq yahtml-menu-map (make-sparse-keymap "yahtml menu"))
yuuji@54: (setq yahtml-menu-map-sectioning (make-sparse-keymap "sectioning menu"))
yuuji@54: (yahtml-define-menu
yuuji@54: yahtml-menu-map-sectioning
yuuji@54: (nreverse
yuuji@54: '((1 "H1" . (lambda () (interactive) (yahtml-insert-begin-end "H1" nil)))
yuuji@54: (2 "H2" . (lambda () (interactive) (yahtml-insert-begin-end "H2" nil)))
yuuji@54: (3 "H3" . (lambda () (interactive) (yahtml-insert-begin-end "H3" nil)))
yuuji@54: (4 "H4" . (lambda () (interactive) (yahtml-insert-begin-end "H4" nil)))
yuuji@54: (5 "H5" . (lambda () (interactive) (yahtml-insert-begin-end "H5" nil)))
yuuji@54: (6 "H6" . (lambda () (interactive) (yahtml-insert-begin-end "H6" nil)))
yuuji@54: )))
yuuji@54: (setq yahtml-menu-map-logical (make-sparse-keymap "logical tags"))
yuuji@54: (yahtml-define-menu
yuuji@54: yahtml-menu-map-logical
yuuji@54: (nreverse
yuuji@54: '((em "Embolden" .
yuuji@54: (lambda () (interactive) (yahtml-insert-tag "EM")))
yuuji@54: (defn "Define a word" .
yuuji@54: (lambda () (interactive) (yahtml-insert-tag "DEFN")))
yuuji@54: (cite "Citation" .
yuuji@54: (lambda () (interactive) (yahtml-insert-tag "CITE")))
yuuji@54: (code "Code" .
yuuji@54: (lambda () (interactive) (yahtml-insert-tag "CODE")))
yuuji@54: (kbd "Keyboard" .
yuuji@54: (lambda () (interactive) (yahtml-insert-tag "KBD")))
yuuji@54: (samp "Sample display" .
yuuji@54: (lambda () (interactive) (yahtml-insert-tag "SAMP")))
yuuji@54: (strong "Strong" .
yuuji@54: (lambda () (interactive) (yahtml-insert-tag "STRONG")))
yuuji@54: (VAR "Variable notation" .
yuuji@54: (lambda () (interactive) (yahtml-insert-tag "VAR")))
yuuji@54: )))
yuuji@54: (setq yahtml-menu-map-typeface (make-sparse-keymap "typeface tags"))
yuuji@54: (yahtml-define-menu
yuuji@54: yahtml-menu-map-typeface
yuuji@54: (nreverse
yuuji@54: '((b "Bold" .
yuuji@54: (lambda () (interactive) (yahtml-insert-tag "B")))
yuuji@54: (i "Italic" .
yuuji@54: (lambda () (interactive) (yahtml-insert-tag "I")))
yuuji@54: (tt "Typewriter" .
yuuji@54: (lambda () (interactive) (yahtml-insert-tag "TT")))
yuuji@54: (u "Underlined" .
yuuji@54: (lambda () (interactive) (yahtml-insert-tag "U")))
yuuji@54: )))
yuuji@54: (setq yahtml-menu-map-listing (make-sparse-keymap "listing"))
yuuji@54: (yahtml-define-menu
yuuji@54: yahtml-menu-map-listing
yuuji@54: (nreverse
yuuji@54: '((ul "Unnumbered" .
yuuji@54: (lambda () (interactive) (yahtml-insert-begin-end "UL" nil)))
yuuji@54: (ol "Numbered" .
yuuji@54: (lambda () (interactive) (yahtml-insert-begin-end "OL" nil)))
yuuji@54: (dl "Description" .
yuuji@54: (lambda () (interactive) (yahtml-insert-begin-end "DL" nil)))
yuuji@54: )))
yuuji@57: (setq yahtml-menu-map-item (make-sparse-keymap "item"))
yuuji@57: (yahtml-define-menu
yuuji@57: yahtml-menu-map-item
yuuji@57: (nreverse
yuuji@57: '((li "Simple item" .
yuuji@57: (lambda () (interactive) (yahtml-insert-single "li")))
yuuji@57: (dt "Define term" .
yuuji@57: (lambda () (interactive) (yahtml-insert-single "dt")))
yuuji@57: (dd "Description of term" .
yuuji@57: (lambda () (interactive) (yahtml-insert-single "dd")))
yuuji@57: )))
yuuji@54: (define-key yahtml-mode-map [menu-bar yahtml]
yuuji@54: (cons "yahtml" yahtml-menu-map))
yuuji@54: (yahtml-define-menu
yuuji@54: yahtml-menu-map
yuuji@54: (nreverse
yuuji@54: (list
yuuji@54: (cons (list 'sect "Sectioning")
yuuji@54: (cons "sectioning" yahtml-menu-map-sectioning))
yuuji@54: (cons (list 'list "Listing")
yuuji@54: (cons "Listing" yahtml-menu-map-listing))
yuuji@57: (cons (list 'item "Item")
yuuji@57: (cons "Itemizing" yahtml-menu-map-item));;;
yuuji@54: (cons (list 'logi "Logical tags")
yuuji@54: (cons "logical" yahtml-menu-map-logical))
yuuji@54: (cons (list 'type "Typeface tags")
yuuji@54: (cons "typeface" yahtml-menu-map-typeface))
yuuji@54: )))
yuuji@54: ))
yuuji@54:
yuuji@54: (defun yahtml-collect-url-history ()
yuuji@54: "Collect urls from global history file."
yuuji@54: (interactive)
yuuji@54: (save-excursion
yuuji@54: (set-buffer
yuuji@54: (find-file-noselect (expand-file-name yahtml-url-history-file)))
yuuji@54: (goto-char (point-min))
yuuji@54: (setq yahtml-urls)
yuuji@54: (message "Collecting global history...")
yuuji@54: (while (re-search-forward "^[A-Za-z]+:" nil t)
yuuji@54: (setq yahtml-urls
yuuji@54: (cons (list
yuuji@54: (buffer-substring
yuuji@54: (progn (beginning-of-line) (point))
yuuji@54: (progn (skip-chars-forward "^ ") (point))))
yuuji@54: yahtml-urls)))
yuuji@54: (message "Collecting global history...Done")))
yuuji@54:
yuuji@57: ;;; ----------- Completion ----------
yuuji@57: (defvar yahtml-last-begend "html")
yuuji@57: (defun yahtml-insert-begend (&optional region)
yuuji@57: "Insert