yuuji@13: ;;; -*- Emacs-Lisp -*-
yuuji@58: ;;; (c ) 1994 by HIROSE Yuuji [yuuji@ae.keio.ac.jp, pcs39334@asciinet.or.jp]
yuuji@59: ;;; Last modified Tue Apr 23 23:13:12 1996 on inspire
yuuji@58: ;;; This package is no longer tentative.
yuuji@54: ;;; $Id$
yuuji@54:
yuuji@58: ;;;[Installation]
yuuji@58: ;;;
yuuji@58: ;;; First, you have to install YaTeX and make sure it works fine. Then
yuuji@58: ;;; put these expressions into your ~/.emacs
yuuji@58: ;;;
yuuji@58: ;;; (setq auto-mode-alist
yuuji@58: ;;; (cons (cons "\\.html$" 'yahtml-mode) auto-mode-alist))
yuuji@58: ;;; (autoload 'yahtml-mode "yahtml" "Yet Another HTML mode" t)
yuuji@58: ;;; (setq yahtml-www-browser "netscape")
yuuji@58: ;;; ;Write your favorite browser. But netscape is advantageous.
yuuji@58: ;;; (setq yahtml-path-url-alist
yuuji@58: ;;; '(("/home/yuuji/public_html" . "http://www.mynet/~yuuji")
yuuji@58: ;;; ("/home/staff/yuuji/html" . "http://www.othernet/~yuuji")))
yuuji@58: ;;; ;Write correspondence alist from ABSOLUTE unix path name to URL path.
yuuji@58: ;;;
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@59: ;;; When input `href=...', you can complete file
yuuji@59: ;;; name or label(href="#foo") by typing TAB.
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@58: ;;; `
' or `
\\|^[ \t]*?\\(h[1-6]\\|p\\|d[ldt]\\|t[rdh]\\|li\\|body\\|html\\|head\\|title\\|ul\\|ol\\|dl\\|pre\\)>") yuuji@59: "*Regexp of html paragraph separater") yuuji@57: (defvar yahtml-paragraph-separate yuuji@57: (concat yuuji@59: "^$\\|<[bh]r>\\|
\\|^[ \t]*?\\(h[1-6]\\|p\\|d[ldt]\\|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@59: (modify-syntax-entry ?\n " " yahtml-syntax-table)
yuuji@54: )
yuuji@54: (defvar yahtml-command-regexp "[A-Za-z0-9]+"
yuuji@54: "Regexp of constituent of html commands.")
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@59: ("textarea")
yuuji@58: ("OrderedList" . "ol")
yuuji@58: ("UnorderedList" . "ul")
yuuji@58: ("DefinitionList" . "dl")
yuuji@59: ("Preformatted" . "pre")
yuuji@59: ("table") ("tr") ("th") ("td")
yuuji@57: ("h1") ("h2") ("h3") ("h4") ("h5") ("h6") ("ul")))
yuuji@57:
yuuji@58: (defvar yahtml-itemizing-regexp
yuuji@58: "\\(ul\\|ul\\|dl\\)"
yuuji@58: "Regexp of itemizing forms")
yuuji@58:
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@58: (defvar yahtml-last-typeface-cmd "address")
yuuji@54:
yuuji@57: (defvar yahtml-single-cmd-table
yuuji@58: '(("hr") ("br") ("option") ("p")
yuuji@58: ("HorizontalLine" . "hr")
yuuji@58: ("BreakLine" . "br")
yuuji@58: ("Paragraph" . "p")
yuuji@58: ("Item" . "li")
yuuji@58: ("DefineTerm" . "dt")
yuuji@58: ("Description" . "dd")
yuuji@58: ("dd") ("dt") ("li")
yuuji@58: )
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@59: "\\<\\(h[1-6]\\|[uod]l\\|body\\|title\\|head\\|table\\|t[rhd]\\|pre\\|a\\|form\\|select\\)\\b")
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@59: (make-local-variable 'YaTeX-struct-begin)
yuuji@59: (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@59: (make-local-variable 'YaTeX-comment-prefix)
yuuji@59: (setq YaTeX-comment-prefix "")
yuuji@58: (make-local-variable 'indent-line-function)
yuuji@58: (setq indent-line-function 'yahtml-indent-line)
yuuji@58: (make-local-variable 'YaTeX-item-regexp)
yuuji@58: (setq YaTeX-item-regexp "<\\(li\\|d[td]\\)>")
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@58: '((1 "H1" . (lambda () (interactive) (yahtml-insert-begend nil "H1")))
yuuji@58: (2 "H2" . (lambda () (interactive) (yahtml-insert-begend nil "H2")))
yuuji@58: (3 "H3" . (lambda () (interactive) (yahtml-insert-begend nil "H3")))
yuuji@58: (4 "H4" . (lambda () (interactive) (yahtml-insert-begend nil "H4")))
yuuji@58: (5 "H5" . (lambda () (interactive) (yahtml-insert-begend nil "H5")))
yuuji@58: (6 "H6" . (lambda () (interactive) (yahtml-insert-begend nil "H6")))
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@58: (lambda () (interactive) (yahtml-insert-tag nil "EM")))
yuuji@54: (defn "Define a word" .
yuuji@58: (lambda () (interactive) (yahtml-insert-tag nil "DEFN")))
yuuji@54: (cite "Citation" .
yuuji@58: (lambda () (interactive) (yahtml-insert-tag nil "CITE")))
yuuji@54: (code "Code" .
yuuji@58: (lambda () (interactive) (yahtml-insert-tag nil "CODE")))
yuuji@54: (kbd "Keyboard" .
yuuji@58: (lambda () (interactive) (yahtml-insert-tag nil "KBD")))
yuuji@54: (samp "Sample display" .
yuuji@58: (lambda () (interactive) (yahtml-insert-tag nil "SAMP")))
yuuji@54: (strong "Strong" .
yuuji@58: (lambda () (interactive) (yahtml-insert-tag nil "STRONG")))
yuuji@54: (VAR "Variable notation" .
yuuji@58: (lambda () (interactive) (yahtml-insert-tag nil "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@58: (lambda () (interactive) (yahtml-insert-tag nil "B")))
yuuji@54: (i "Italic" .
yuuji@58: (lambda () (interactive) (yahtml-insert-tag nil "I")))
yuuji@54: (tt "Typewriter" .
yuuji@58: (lambda () (interactive) (yahtml-insert-tag nil "TT")))
yuuji@54: (u "Underlined" .
yuuji@58: (lambda () (interactive) (yahtml-insert-tag nil "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@58: '((ul "Unordered" .
yuuji@58: (lambda () (interactive) (yahtml-insert-begend nil "UL")))
yuuji@58: (ol "Ordered" .
yuuji@58: (lambda () (interactive) (yahtml-insert-begend nil "OL")))
yuuji@58: (dl "Definition" .
yuuji@58: (lambda () (interactive) (yahtml-insert-begend nil "DL")))
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@58: (let ((keys (where-is-internal 'fill-paragraph global-map)))
yuuji@58: (while keys
yuuji@58: (define-key yahtml-mode-map (car keys) 'yahtml-fill-paragraph)
yuuji@58: (setq keys (cdr keys))))
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@58: (defun yahtml-insert-begend (&optional region env)
yuuji@57: "Insert