yuuji@13: ;;; -*- Emacs-Lisp -*- yuuji@16: ;;; (c ) 1994 by HIROSE Yuuji [yuuji@ae.keio.ac.jp, pcs39334@ascii-net.or.jp] yuuji@54: ;;; Last modified Mon Apr 24 22:52:17 1995 on pajero 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@54: ;;; normally requires newline. yuuji@54: ;;; * [prefix] s Complete declarative notations such as yuuji@54: ;;; ` .... ' yuuji@54: ;;; * [prefix] l Complete typeface-changing commands such as yuuji@54: ;;; ` ... ' or ` ... ' yuuji@54: ;;; * menu-bar yahtml Complete all by selecting a menu item (Though I yuuji@54: ;;; hate menu, this is most useful) yuuji@54: ;;; yuuji@54: ;;; NOTE! This program is truly tentative. If you find some bright yuuji@54: ;;; future with this, please send me a mail to drive me to maintain this :) yuuji@54: yuuji@13: yuuji@13: (require 'yatex) yuuji@13: (defvar yahtml-prefix-map (copy-keymap YaTeX-prefix-map)) yuuji@13: (defvar yahtml-mode-map nil yuuji@13: "Keymap used in yahtml-mode.") yuuji@13: (if yahtml-mode-map nil yuuji@13: (setq yahtml-mode-map (make-sparse-keymap)) yuuji@54: (define-key yahtml-mode-map YaTeX-prefix yahtml-prefix-map) yuuji@54: (define-key yahtml-mode-map "\M-\C-@" 'YaTeX-mark-environment) yuuji@54: (define-key yahtml-mode-map "\M-\C-a" 'YaTeX-beginning-of-environment) yuuji@54: (define-key yahtml-mode-map "\M-\C-e" 'YaTeX-end-of-environment)) yuuji@54: 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@54: yuuji@54: ;;; Completion tables for `form' yuuji@54: (defvar yahtml-form-table '(("a") ("form"))) 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@54: '(("html") ("head") ("title") ("body") ("dl") yuuji@54: ("h1") ("h2") ("h3") ("h4") ("h5") ("h6"))) yuuji@54: yuuji@54: ;;; Completion tables for typeface designator yuuji@54: (defvar yahtml-typeface-table yuuji@54: '(("defn") ("em") ("cite") ("code") ("kbd") ("samp") yuuji@54: ("strong") ("var") ("b") ("i") ("tt") ("u")) 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@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@13: (defun yahtml-mode () yuuji@13: (interactive) yuuji@13: (yatex-mode) yuuji@13: (setq major-mode 'yahtml-mode yuuji@13: mode-name "yahtml") yuuji@54: (make-local-variable 'YaTeX-ec) (setq YaTeX-ec "") yuuji@54: (make-local-variable 'YaTeX-struct-begin) (setq YaTeX-struct-begin "<%1>") yuuji@54: (make-local-variable 'YaTeX-struct-end) (setq YaTeX-struct-end "") yuuji@54: (mapcar 'make-local-variable yuuji@54: '(env-table user-env-table tmp-env-table)) yuuji@54: (setq env-table yahtml-env-table) yuuji@54: (mapcar 'make-local-variable yuuji@54: '(singlecmd-table user-singlecmd-table tmp-singlecmd-table)) yuuji@54: (make-local-variable 'YaTeX-struct-name-regexp) yuuji@54: (setq YaTeX-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@13: (setq YaTeX-prefix-map yahtml-prefix-map) yuuji@54: (set-syntax-table yahtml-syntax-table) yuuji@13: (use-local-map yahtml-mode-map) yuuji@54: (YaTeX-define-key "s" 'yahtml-insert-form) yuuji@54: (YaTeX-define-key "l" 'yahtml-insert-tag) yuuji@54: (if YaTeX-no-begend-shortcut nil yuuji@54: (YaTeX-define-begend-key "bh" "HTML") yuuji@54: (YaTeX-define-begend-key "bH" "HEAD") yuuji@54: (YaTeX-define-begend-key "bt" "TITLE") yuuji@54: (YaTeX-define-begend-key "bb" "BODY") yuuji@54: (YaTeX-define-begend-key "bd" "DL") yuuji@54: (YaTeX-define-begend-key "b1" "H1") yuuji@54: (YaTeX-define-begend-key "b2" "H2") yuuji@54: (YaTeX-define-begend-key "b3" "H3")) 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@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@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@54: (defun yahtml-insert-form (&optional form) yuuji@54: "Insert
." yuuji@54: (interactive) yuuji@54: (or form yuuji@54: (setq form yuuji@54: (YaTeX-cplread-with-learning yuuji@54: "Form: " yuuji@54: 'yahtml-form-table 'yahtml-user-form-table yuuji@54: 'yahtml-tmp-form-table))) yuuji@54: (let ((p (point))) yuuji@54: (insert (format "<%s%s>\n" form (yahtml-addin (downcase form)))) yuuji@54: (indent-relative-maybe) yuuji@54: (save-excursion (insert (format "" form))) yuuji@54: (if (search-backward "\"\"" p t) (forward-char 1)))) yuuji@54: yuuji@54: (defun yahtml-addin (form) yuuji@54: "Check add-in function's existence and call it if exists." yuuji@54: (let ((addin (concat "yahtml::" form))) yuuji@54: (if (and (intern-soft addin) (fboundp (intern-soft addin))) yuuji@54: (concat " " (funcall (intern addin))) yuuji@54: ""))) yuuji@54: yuuji@54: (defun yahtml::a () yuuji@54: "Add-in function for " yuuji@54: (or yahtml-urls (yahtml-collect-url-history)) yuuji@54: (concat "href=\"" yuuji@54: (completing-read "href: " yahtml-urls) yuuji@54: "\"")) yuuji@54: yuuji@54: (defun yahtml-insert-begin-end (env &optional region-mode) yuuji@54: "Insert \\n by calling YaTeX-insert-begin-end." yuuji@54: (interactive "sEnv: ") yuuji@54: (setq env (funcall (if yahtml-prefer-upcases 'upcase 'downcase) env)) yuuji@54: (YaTeX-insert-begin-end env region-mode)) yuuji@54: yuuji@54: (defun yahtml-insert-tag (&optional tag) yuuji@54: "Insert and put cursor inside of them." yuuji@54: (interactive) yuuji@54: (or tag yuuji@54: (setq tag yuuji@54: (YaTeX-cplread-with-learning yuuji@54: "Tag: " yuuji@54: 'yahtml-typeface-table 'yahtml-user-typeface-table yuuji@54: 'yahtml-tmp-typeface-table))) yuuji@54: (setq tag (funcall (if yahtml-prefer-upcases 'upcase 'downcase) tag)) yuuji@54: (insert (format "<%s> " tag)) yuuji@54: (save-excursion (insert (format "" tag)))) yuuji@54: yuuji@54: (provide 'yahtml) yuuji@54: yuuji@54: ; Local variables: yuuji@54: ; fill-prefix: ";;; " yuuji@54: ; paragraph-start: "^$\\| \\|;;;$" yuuji@54: ; paragraph-separate: "^$\\| \\|;;;$" yuuji@54: ; End: