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 `
' 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@57: (defvar yahtml-prefix-map nil) yuuji@57: (defvar yahtml-mode-map nil "Keymap used in yahtml-mode.") yuuji@57: yuuji@57: (defun yahtml-define-begend-key-normal (key env &optional map) yuuji@57: "Define short cut yahtml-insert-begin-end key." yuuji@57: (YaTeX-define-key yuuji@57: key yuuji@57: (list 'lambda '(arg) '(interactive "P") yuuji@57: (list 'yahtml-insert-begin-end env 'arg)) yuuji@57: map)) yuuji@57: yuuji@57: (defun yahtml-define-begend-region-key (key env &optional map) yuuji@57: "Define short cut yahtml-insert-begin-end-region key." yuuji@57: (YaTeX-define-key key (list 'lambda nil '(interactive) yuuji@57: (list 'yahtml-insert-begin-end env t)) map)) yuuji@57: yuuji@57: (defun yahtml-define-begend-key (key env &optional map) yuuji@57: "Define short cut key for begin type completion both for yuuji@57: normal and region mode. To customize yahtml, user should use this function." yuuji@57: (yahtml-define-begend-key-normal key env map) yuuji@57: (if YaTeX-inhibit-prefix-letter nil yuuji@57: (yahtml-define-begend-region-key yuuji@57: (concat (upcase (substring key 0 1)) (substring key 1)) env))) yuuji@57: yuuji@57: yuuji@13: (if yahtml-mode-map nil yuuji@57: (setq yahtml-mode-map (make-sparse-keymap) yuuji@57: yahtml-prefix-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@57: (define-key yahtml-mode-map "\M-\C-e" 'YaTeX-end-of-environment) yuuji@57: (define-key yahtml-mode-map "\C-i" 'YaTeX-indent-line) yuuji@57: (define-key yahtml-mode-map YaTeX-prefix yahtml-prefix-map) yuuji@57: (let ((map yahtml-prefix-map)) yuuji@57: (YaTeX-define-key "^" 'yahtml-visit-main map) yuuji@57: (YaTeX-define-key "4^" 'yahtml-visit-main-other-window map) yuuji@57: (YaTeX-define-key "4g" 'yahtml-goto-corresponding-*-other-window map) yuuji@57: (YaTeX-define-key "44" 'YaTeX-switch-to-window map) yuuji@57: (and YaTeX-emacs-19 window-system yuuji@57: (progn yuuji@57: (YaTeX-define-key "5^" 'yahtml-visit-main-other-frame map) yuuji@57: (YaTeX-define-key "5g" 'yahtml-goto-corresponding-*-other-frame map) yuuji@57: (YaTeX-define-key "55" 'YaTeX-switch-to-window map))) yuuji@57: (YaTeX-define-key "v" 'YaTeX-version map) yuuji@57: (YaTeX-define-key "}" 'YaTeX-insert-braces-region map) yuuji@57: (YaTeX-define-key "]" 'YaTeX-insert-brackets-region map) yuuji@57: (YaTeX-define-key ")" 'YaTeX-insert-parens-region map) yuuji@57: (YaTeX-define-key "s" 'yahtml-insert-form map) yuuji@57: (YaTeX-define-key "l" 'yahtml-insert-tag map) yuuji@57: (YaTeX-define-key "m" 'yahtml-insert-single map) yuuji@57: (YaTeX-define-key "n" '(lambda () (interactive) (insert "
\n")) map) yuuji@57: (if YaTeX-no-begend-shortcut yuuji@57: (progn yuuji@57: (YaTeX-define-key "B" 'yahtml-insert-begend-region map) yuuji@57: (YaTeX-define-key "b" 'yahtml-insert-begend map)) yuuji@57: (yahtml-define-begend-key "bh" "HTML" map) yuuji@57: (yahtml-define-begend-key "bH" "HEAD" map) yuuji@57: (yahtml-define-begend-key "bt" "TITLE" map) yuuji@57: (yahtml-define-begend-key "bb" "BODY" map) yuuji@57: (yahtml-define-begend-key "bd" "DL" map) yuuji@57: (yahtml-define-begend-key "b1" "H1" map) yuuji@57: (yahtml-define-begend-key "b2" "H2" map) yuuji@57: (yahtml-define-begend-key "b3" "H3" map) yuuji@57: (yahtml-define-begend-key "ba" "a" map) yuuji@57: (yahtml-define-begend-key "bf" "form" map) yuuji@57: (yahtml-define-begend-key "bs" "select" map) yuuji@57: (YaTeX-define-key "b " 'yahtml-insert-begend map) yuuji@57: (YaTeX-define-key "B " 'yahtml-insert-begend map) yuuji@57: ) yuuji@57: (YaTeX-define-key "e" 'yahtml-end-environment map) yuuji@57: (YaTeX-define-key ">" 'yahtml-comment-region map) yuuji@57: (YaTeX-define-key "<" 'yahtml-uncomment-region map) yuuji@57: (YaTeX-define-key "g" 'yahtml-goto-corresponding-* map) yuuji@57: ) yuuji@57: ) yuuji@54: yuuji@57: (defvar yahtml-paragraph-separate yuuji@57: (concat yuuji@57: "^$\\|
\\|

\\|^[ \t]*") 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 "") 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 ... ." yuuji@57: (interactive "P") yuuji@57: (let ((cmd (YaTeX-cplread-with-learning yuuji@57: (format "Environment(default %s): " yahtml-last-begend) yuuji@57: 'yahtml-env-table 'yahtml-user-env-table 'yahtml-tmp-env-table)) yuuji@57: (bolp (bolp))) yuuji@57: (if (string< "" cmd) (setq yahtml-last-begend cmd)) yuuji@57: (setq cmd yahtml-last-begend) yuuji@57: (if region yuuji@57: (let ((beg (region-beginning)) yuuji@57: (end (region-end)) yuuji@57: (addin (yahtml-addin cmd))) yuuji@57: (goto-char end) yuuji@57: (insert (format "%s" cmd (if bolp "\n" ""))) yuuji@57: (goto-char beg) yuuji@57: (insert (format "<%s%s>%s" cmd addin (if bolp "\n" "")))) yuuji@57: (insert (format "<%s%s" cmd (yahtml-addin cmd))) yuuji@57: (if bolp (progn (insert (format ">\n\n" cmd cmd)) yuuji@57: (forward-line -1)) yuuji@57: (insert ">") yuuji@57: (save-excursion (insert (format "" cmd))))))) yuuji@57: yuuji@57: (defun yahtml-insert-begend-region () yuuji@57: "Call yahtml-insert-begend in the region mode." yuuji@57: (interactive) yuuji@57: (yahtml-insert-begend t)) yuuji@57: yuuji@57: yuuji@54: (defun yahtml-insert-form (&optional form) yuuji@57: "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@57: (let ((p (point)) q) yuuji@57: (insert (format "<%s%s>" form (yahtml-addin (downcase form)))) yuuji@57: ;;(indent-relative-maybe) yuuji@57: (if (cdr (assoc form yahtml-form-table)) yuuji@57: (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@57: (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@57: (defun yahtml:a () yuuji@54: "Add-in function for " yuuji@57: ; (or yahtml-urls (yahtml-collect-url-history)) yuuji@57: ; (concat "href=\"" yuuji@57: ; (completing-read "href: " yahtml-urls) yuuji@57: ; "\"") yuuji@57: (concat "href=\"" (read-file-name "href: " "" nil nil "") "\"") yuuji@57: ) yuuji@57: yuuji@57: (defun yahtml:img () yuuji@57: "Add-in function for " yuuji@54: (or yahtml-urls (yahtml-collect-url-history)) yuuji@57: (let ((src (read-file-name "src: " "" nil t "")) yuuji@57: (alg (completing-read "align: " '(("top") ("middle") ("bottom"))))) yuuji@57: (concat "src=\"" src "\"" yuuji@57: (if (string< "" alg) (concat " align=\"" alg "\""))))) yuuji@57: yuuji@57: (defun yahtml:form () yuuji@57: "Add-in function `form' input format" yuuji@57: (concat yuuji@57: " method=" (completing-read "Method: " '(("POST") ("GET")) nil t) yuuji@57: " action=\"" (read-string "Action: ") "\"" yuuji@57: )) yuuji@57: yuuji@57: (defun yahtml:select () yuuji@57: "Add-in function for `select' input format" yuuji@57: (setq yahtml-last-single-cmd "option") yuuji@57: (concat " name=\"" (read-string "name: ") "\"")) yuuji@57: yuuji@57: (defvar yahtml-input-types yuuji@57: '(("text") ("password") ("checkbox") ("radio") ("submit") yuuji@57: ("reset") ("image") ("hidden"))) yuuji@57: yuuji@57: (defun yahtml:input () yuuji@57: "Add-in function for `input' form" yuuji@57: (let (name type value checked (size "") (maxlength "")) yuuji@57: (setq name (read-string "name: ") yuuji@57: type (completing-read "type (default=text): " yuuji@57: yahtml-input-types nil t) yuuji@57: value (read-string "value: ")) yuuji@57: (if (string-match "text\\|password\\|^$" type) yuuji@57: (setq size (read-string "size: ") yuuji@57: maxlength (read-string "maxlength: "))) yuuji@57: (concat yuuji@57: "name=\"" name "\"" yuuji@57: (if (string< "" type) (concat " type=\"" type "\"")) yuuji@57: (if (string< "" value) (concat " value=\"" value "\"")) yuuji@57: (if (string< "" size) (concat " size=\"" size "\"")) yuuji@57: (if (string< "" maxlength) (concat " maxlength=\"" maxlength "\"")) yuuji@57: ))) yuuji@57: 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@57: (defun yahtml-insert-tag (tag) yuuji@54: "Insert and put cursor inside of them." yuuji@57: (interactive yuuji@57: (list yuuji@57: (YaTeX-cplread-with-learning yuuji@57: "Tag: " yuuji@57: 'yahtml-typeface-table 'yahtml-user-typeface-table yuuji@57: '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@57: (defun yahtml-insert-single (cmd) yuuji@57: "Insert ." yuuji@57: (interactive yuuji@57: (list (YaTeX-cplread-with-learning yuuji@57: (format "Command%s: " yuuji@57: (if yahtml-last-single-cmd yuuji@57: (concat "(default " yahtml-last-single-cmd ")") "")) yuuji@57: 'yahtml-single-cmd-table 'yahtml-user-single-cmd-table yuuji@57: 'yahtml-tmp-single-cmd-table))) yuuji@57: (setq cmd (funcall (if yahtml-prefer-upcases 'upcase 'downcase) cmd)) yuuji@57: (if (string< "" cmd) (setq yahtml-last-single-cmd cmd)) yuuji@57: (insert (format "<%s>" yahtml-last-single-cmd))) yuuji@57: yuuji@57: ;;; ---------- Jump ---------- yuuji@57: (defun yahtml-on-href-p () yuuji@57: "Check if point is on href clause." yuuji@57: (let ((p (point)) cmd) yuuji@57: (save-excursion yuuji@57: (or (bobp) (skip-chars-backward "^ \t")) yuuji@57: (and (looking-at "href\\s *=\\s *\"?\\([^\"]+\\)\"?") yuuji@57: (< p (match-end 0)) yuuji@57: (YaTeX-match-string 1))))) yuuji@57: yuuji@57: (defun yahtml-goto-corresponding-href (&optional other) yuuji@57: "Go to corresponding name." yuuji@57: (let ((href (yahtml-on-href-p)) file name) yuuji@57: (if href yuuji@57: (cond yuuji@57: ((string-match "^http:" href) yuuji@57: (message "Sorry, jump across http is not supported.")) yuuji@57: (t (setq file (substring href 0 (string-match "#" href))) yuuji@57: (if (string-match "#" href) yuuji@57: (setq name (substring href (1+ (string-match "#" href))))) yuuji@57: (if (string< "" file) yuuji@57: (progn yuuji@57: (if (string-match "/$" file) yuuji@57: (setq file (concat file "index.html"))) yuuji@57: (if other (YaTeX-switch-to-buffer-other-window file) yuuji@57: (YaTeX-switch-to-buffer file)))) yuuji@57: (if name yuuji@57: (progn (set-mark-command nil) (yahtml-jump-to-name name))) yuuji@57: t))))) yuuji@57: yuuji@57: (defun yahtml-jump-to-name (name) yuuji@57: "Jump to html's named tag." yuuji@57: (setq name (format "name\\s *=\\s *\"?%s\"?" name)) yuuji@57: (or (and (re-search-forward name nil t) (goto-char (match-beginning 0))) yuuji@57: (and (re-search-backward name nil t) (goto-char (match-beginning 0))) yuuji@57: (message "Named tag `%s' not found" (substring href 1)))) yuuji@57: yuuji@57: (defun yahtml-on-begend-p (&optional p) yuuji@57: "Check if point is on begend clause." yuuji@57: (let ((p (point)) cmd) yuuji@57: (save-excursion yuuji@57: (if p (goto-char p)) yuuji@57: (if (= (char-after (point)) ?<) (forward-char 1)) yuuji@57: (if (and (re-search-backward "<" nil t) yuuji@57: (looking-at yuuji@57: (concat "<\\(/?" yahtml-command-regexp "\\)\\b")) yuuji@57: (condition-case nil yuuji@57: (forward-list 1)) yuuji@57: (< p (point))) yuuji@57: (YaTeX-match-string 1))))) yuuji@57: yuuji@57: (defun yahtml-goto-corresponding-begend () yuuji@57: (let ((cmd (yahtml-on-begend-p))) yuuji@57: (if cmd yuuji@57: (progn yuuji@57: (if (= (aref cmd 0) ?/) ;on line yuuji@57: (re-search-backward (format "<%s" (substring cmd 1))) yuuji@57: (re-search-forward (format "" comment) yuuji@57: ;; include&exec yuuji@57: ("" include) yuuji@57: ;; string yuuji@57: (hilit-string-find 39 string) yuuji@57: (yahtml-hilit-region-tag "\\(em\\|strong\\)" bold) yuuji@57: ("" 0 decl) yuuji@57: ("<\\(di\\|dt\\|li\\|dd\\)>" 0 label) yuuji@57: ("" crossref) yuuji@57: ("" 0 decl) yuuji@57: (" form." yuuji@57: (if (re-search-forward (concat "<" tag ">") nil t) yuuji@57: (let ((m0 (match-beginning 0))) yuuji@57: (skip-chars-forward " \t\n") yuuji@57: (cons (point) yuuji@57: (progn (re-search-forward (concat "") nil t) yuuji@57: (1- (match-beginning 0))))))) yuuji@57: yuuji@57: ;(setq hilit-patterns-alist (delq (assq 'yahtml-mode hilit-patterns-alist) hilit-patterns-alist)) yuuji@57: (cond yuuji@57: ((and (featurep 'hilit19) (featurep 'yatex19)) yuuji@57: (or (assq 'yahtml-mode hilit-patterns-alist) yuuji@57: (setq hilit-patterns-alist yuuji@57: (cons (cons 'yahtml-mode yahtml-hilit-patterns-alist) yuuji@57: hilit-patterns-alist))))) yuuji@57: 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: