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 `
or
  • ...' yuuji@59: ;;; * M-RET Intelligent newline; if current TAG is one of yuuji@59: ;;; ul, ol, or dl. insert newline and
  • or yuuji@59: ;;;
    or
    suitable for current condition. yuuji@54: ;;; * menu-bar yahtml Complete all by selecting a menu item (Though I yuuji@54: ;;; hate menu, this is most useful) yuuji@58: ;;; * [prefix] g Goto corresponding Tag or HREF such as yuuji@59: ;;;
    <->
    or href="xxx". yuuji@59: ;;; Or invoke image viewer if point is on . yuuji@58: ;;; * [prefix] k Kill html tags on the point. If you provide yuuji@58: ;;; universal-argument, kill surrounded contents too. yuuji@58: ;;; * [prefix] c Change html tags on the point. yuuji@59: ;;; When typeing [prefix] c on `href="xxx"', you can yuuji@59: ;;; change the reference link with completion. yuuji@58: ;;; * [prefix] t b View current html with WWW browser yuuji@58: ;;; (To activate this, never fail to set the lisp yuuji@58: ;;; variable yahtml-www-browser. Recommended value yuuji@58: ;;; is "netscape") yuuji@59: ;;; * [prefix] a YaTeX's accent mark's equivalent of yahtml. yuuji@59: ;;; This function can input $lt, $gt or so. yuuji@58: ;;; 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@58: (defvar yahtml-image-viewer "xv" "*Image viewer program") yuuji@58: (defvar yahtml-www-browser "netscape" yuuji@58: "*WWW Browser command") yuuji@58: (defvar yahtml-kanji-code 2 yuuji@58: "Kanji coding system of html file; 1=sjis, 2=jis, 3=euc") yuuji@58: ;;(defvar yahtml-www-server "www" "*Host name of your domain's WWW server") yuuji@58: (defvar yahtml-path-url-alist nil yuuji@58: "*Alist of unix path name vs. URL name of WWW server. yuuji@58: Ex. yuuji@58: '((\"/usr/home/yuuji/http\" . \"http://www.comp.ae.keio.ac.jp/~yuuji\") yuuji@58: (\"/usr/home/yuuji/darts/http\" . \"http://inspire.comp.ae.keio.ac.jp/~darts\"))") yuuji@58: (defvar yahtml-directory-index "index.html" yuuji@58: "*Directory index file name; yuuji@58: Consult your site's WWW administrator.") 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@58: (define-key yahtml-mode-map "\M-\C-@" 'yahtml-mark-begend) yuuji@58: (if (and (boundp 'window-system) (eq window-system 'x) YaTeX-emacs-19) yuuji@58: (define-key yahtml-mode-map [?\M-\C- ] 'yahtml-mark-begend)) 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@58: (define-key yahtml-mode-map "\M-\C-m" 'yahtml-intelligent-newline) yuuji@58: (define-key yahtml-mode-map "\C-i" 'yahtml-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@59: (yahtml-define-begend-key "bT" "table" 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@58: (YaTeX-define-key "B " 'yahtml-insert-begend-region map) yuuji@57: ) yuuji@58: (YaTeX-define-key "e" 'YaTeX-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@58: (YaTeX-define-key "k" 'yahtml-kill-* map) yuuji@58: (YaTeX-define-key "c" 'yahtml-change-* map) yuuji@58: (YaTeX-define-key "t" 'yahtml-browse-menu map) yuuji@59: (YaTeX-define-key "a" 'yahtml-complete-mark map) yuuji@58: ;;;;;(YaTeX-define-key "i" 'yahtml-fill-item map) yuuji@57: ) yuuji@57: ) yuuji@54: yuuji@59: (defvar yahtml-paragraph-start yuuji@59: (concat yuuji@59: "^$\\|<[bh]r>\\|

    \\|^[ \t]*") yuuji@59: "*Regexp of html paragraph separater") yuuji@57: (defvar yahtml-paragraph-separate yuuji@57: (concat yuuji@59: "^$\\|<[bh]r>\\|

    \\|^[ \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@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 "") 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 ... ." yuuji@57: (interactive "P") yuuji@58: (let*((completion-ignore-case t) yuuji@58: (cmd yuuji@58: (or env yuuji@58: (YaTeX-cplread-with-learning yuuji@57: (format "Environment(default %s): " yahtml-last-begend) yuuji@58: 'yahtml-env-table 'yahtml-user-env-table 'yahtml-tmp-env-table))) yuuji@58: (bolp (save-excursion yuuji@58: (skip-chars-backward " \t" (point-beginning-of-line)) (bolp))) yuuji@58: (cc (current-column))) yuuji@57: (if (string< "" cmd) (setq yahtml-last-begend cmd)) yuuji@58: (setq yahtml-last-begend yuuji@58: (or (cdr (assoc yahtml-last-begend yahtml-env-table)) yuuji@58: yahtml-last-begend)) 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@58: (insert (format "<%s%s>" cmd (yahtml-addin cmd))) yuuji@58: (save-excursion yuuji@58: (if bolp (progn yuuji@58: (insert "\n") yuuji@58: (indent-to-column cc) yuuji@58: (insert (format "" cmd))) yuuji@58: (insert (format "" cmd)))) yuuji@58: (if bolp (yahtml-intelligent-newline nil))))) 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@58: (insert (format "<%s%s>" form (yahtml-addin 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@59: ;;; ---------- Add-in ---------- yuuji@54: (defun yahtml-addin (form) yuuji@54: "Check add-in function's existence and call it if exists." yuuji@58: (let ((addin (concat "yahtml:" (downcase form))) s) yuuji@58: (if (and (intern-soft addin) (fboundp (intern-soft addin)) yuuji@58: (stringp (setq s (funcall (intern addin)))) yuuji@58: (string< "" s)) yuuji@58: (concat " " s) yuuji@54: ""))) yuuji@54: yuuji@59: yuuji@59: (defvar yahtml-completing-buffer nil) yuuji@59: (defun yahtml-collect-labels (&optional file) yuuji@59: "Collect current buffers label (). yuuji@59: If optional argument FILE is specified collect labels in FILE." yuuji@59: (let (list) yuuji@59: (save-excursion yuuji@59: (set-buffer yahtml-completing-buffer) yuuji@59: (if file (set-buffer (find-file-noselect file))) yuuji@59: (save-excursion yuuji@59: (goto-char (point-min)) yuuji@59: (while (re-search-forward "]+\\)\"?>") yuuji@59: (setq list (cons yuuji@59: (list (concat "#" (YaTeX-match-string 1))) yuuji@59: list)))) yuuji@59: list))) yuuji@59: ) yuuji@59: yuuji@58: (defvar yahtml-url-completion-map nil "Key map used in URL completion buffer") yuuji@58: (if yahtml-url-completion-map nil yuuji@58: (setq yahtml-url-completion-map yuuji@58: (copy-keymap minibuffer-local-completion-map)) yuuji@58: (define-key yahtml-url-completion-map "\t" 'yahtml-complete-url) yuuji@58: (define-key yahtml-url-completion-map " " 'yahtml-complete-url) yuuji@58: ) yuuji@58: yuuji@58: (defun yahtml-complete-url () yuuji@58: "Complete external URL from history or local file name." yuuji@58: (interactive) yuuji@59: (let (initial i2 cmpl path dir file listfunc beg labels (p (point))) yuuji@58: (setq initial (buffer-string)) yuuji@58: (cond yuuji@58: ((string-match "^http:" initial) yuuji@58: (setq cmpl (try-completion initial yahtml-urls) yuuji@58: listfunc (list 'lambda nil yuuji@58: (list 'all-completions initial 'yahtml-urls)) yuuji@58: beg (point-min))) yuuji@59: ((setq beg (string-match "#" initial)) yuuji@59: (or (equal beg 0) ;begin with # yuuji@59: (progn yuuji@59: (setq path (substring initial 0 beg)) yuuji@59: (if (string-match "^/" path) yuuji@59: (setq path (yahtml-url-to-path path))))) yuuji@59: (setq initial (substring initial beg)) yuuji@59: (setq labels (yahtml-collect-labels path) yuuji@59: cmpl (try-completion initial labels) yuuji@59: listfunc (list 'lambda () yuuji@59: (list 'all-completions yuuji@59: initial (list 'quote labels))) yuuji@59: beg (+ (point-min) beg))) yuuji@58: (t yuuji@58: (setq path (if (string-match "^/" initial) yuuji@58: (yahtml-url-to-path initial) yuuji@58: initial)) yuuji@58: (setq dir (or (file-name-directory path) ".") yuuji@58: file (file-name-nondirectory path) yuuji@58: initial file yuuji@58: cmpl (file-name-completion file dir) yuuji@58: listfunc (list 'lambda nil yuuji@58: (list 'file-name-all-completions yuuji@58: file dir)) yuuji@58: beg (save-excursion (skip-chars-backward "^/") (point))))) yuuji@58: (cond yuuji@58: ((stringp cmpl) yuuji@58: (if (string= initial cmpl) yuuji@58: (with-output-to-temp-buffer "*Completions*" yuuji@58: (princ "Possible completinos are:\n") yuuji@58: (princ yuuji@58: (mapconcat '(lambda (x) x) (funcall listfunc) "\n"))) yuuji@58: (delete-region (point) beg) yuuji@58: (insert cmpl))) yuuji@58: ((null cmpl) yuuji@58: (ding)) yuuji@58: ((eq t cmpl) yuuji@58: (save-excursion yuuji@58: (unwind-protect yuuji@58: (progn yuuji@58: (goto-char p) yuuji@58: (insert " [Sole completion]")) yuuji@58: (delete-region p (point-max)))))))) yuuji@58: yuuji@57: (defun yahtml:a () yuuji@54: "Add-in function for " yuuji@58: (or yahtml-urls (yahtml-collect-url-history)) yuuji@59: (setq yahtml-completing-buffer (current-buffer)) yuuji@57: ; (concat "href=\"" yuuji@57: ; (completing-read "href: " yahtml-urls) yuuji@57: ; "\"") yuuji@58: (message "(H)ref (N)ame?") yuuji@58: (cond yuuji@59: ((string-match "[nN]" (char-to-string (read-char))) yuuji@59: (concat "name=\"" (read-string "name: ") "\"")) yuuji@59: (t yuuji@58: (concat "href=\"" yuuji@58: (read-from-minibuffer "href: " "" yahtml-url-completion-map) yuuji@59: "\"")))) yuuji@57: yuuji@57: (defun yahtml:img () yuuji@57: "Add-in function for " yuuji@54: (or yahtml-urls (yahtml-collect-url-history)) yuuji@58: (let ((src (read-file-name "src: " "" nil nil "")) yuuji@59: (alg (completing-read "align: " '(("top") ("middle") ("bottom")))) yuuji@59: (alt (read-string "alt: "))) yuuji@57: (concat "src=\"" src "\"" yuuji@59: (if (string< "" alg) (concat " align=\"" alg "\"")) yuuji@59: (if (string< "" alt) (concat " alt=\"" alt "\""))))) 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@58: (defun yahtml:ol () yuuji@58: (setq yahtml-last-single-cmd "li") "") yuuji@58: (defun yahtml:ul () yuuji@58: (setq yahtml-last-single-cmd "li") "") yuuji@58: (defun yahtml:dl () yuuji@58: (setq yahtml-last-single-cmd "dt") "") yuuji@58: (defun yahtml:dt () yuuji@58: (setq yahtml-last-single-cmd "dd") "") yuuji@58: yuuji@58: 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@59: yuuji@59: (defun yahtml:textarea () yuuji@59: "Add-in function for `textarea'" yuuji@59: (interactive) yuuji@59: (let (name rows cols) yuuji@59: (setq name (read-string "Name: ") yuuji@59: cols (read-string "Columns: " yuuji@59: rows (read-string "Rows: "))) yuuji@59: (concat yuuji@59: (concat (if yahtml-prefer-upcases "NAME=" "name=") yuuji@59: "\"" name "\"") yuuji@59: (if (string< "" cols) yuuji@59: (concat " " (if yahtml-prefer-upcases "COLS" "cols") "=" cols)) yuuji@59: (if (string< "" rows) yuuji@59: (concat " " (if yahtml-prefer-upcases "ROWS" "rows") "=" rows))))) yuuji@59: yuuji@59: yuuji@59: ;;; ---------- Simple tag ---------- yuuji@58: (defun yahtml-insert-tag (region-mode &optional tag) yuuji@54: "Insert and put cursor inside of them." yuuji@58: (interactive "P") yuuji@58: (or tag yuuji@58: (setq tag yuuji@58: (YaTeX-cplread-with-learning yuuji@58: (format "Tag %s(default %s): " yuuji@58: (if region-mode "region: " "") yahtml-last-typeface-cmd) yuuji@58: 'yahtml-typeface-table 'yahtml-user-typeface-table yuuji@58: 'yahtml-tmp-typeface-table))) yuuji@58: (if (string= "" tag) (setq tag yahtml-last-typeface-cmd)) yuuji@58: (setq tag (funcall (if yahtml-prefer-upcases 'upcase 'downcase) tag) yuuji@58: yahtml-last-typeface-cmd tag) yuuji@58: (if region-mode yuuji@58: (if (if (string< "19" emacs-version) (mark t) (mark)) yuuji@58: (save-excursion yuuji@58: (if (> (point) (mark)) (exchange-point-and-mark)) yuuji@58: (insert "<" tag ">") yuuji@58: (exchange-point-and-mark) yuuji@58: (insert "")) yuuji@58: (message "No mark set now")) yuuji@58: (insert (format "<%s> " tag)) yuuji@58: (save-excursion (insert (format "" tag))))) yuuji@54: yuuji@57: (defun yahtml-insert-single (cmd) yuuji@57: "Insert ." yuuji@57: (interactive yuuji@58: (list yuuji@58: (let ((completion-ignore-case t)) yuuji@58: (YaTeX-cplread-with-learning yuuji@58: (format "Command%s: " yuuji@58: (if yahtml-last-single-cmd yuuji@58: (concat "(default " yahtml-last-single-cmd ")") "")) yuuji@58: 'yahtml-single-cmd-table 'yahtml-user-single-cmd-table yuuji@58: 'yahtml-tmp-single-cmd-table)))) yuuji@58: (if (string< "" cmd) (setq yahtml-last-single-cmd cmd)) yuuji@57: (setq cmd (funcall (if yahtml-prefer-upcases 'upcase 'downcase) cmd)) yuuji@58: (setq yahtml-last-single-cmd yuuji@58: (or (cdr (assoc yahtml-last-single-cmd yahtml-single-cmd-table)) yuuji@58: yahtml-last-single-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@58: (or (bobp) (skip-chars-backward "^ \t\n")) yuuji@58: (and (looking-at "href\\s *=\\s *\"?\\([^\"> \t\n]+\\)\"?") yuuji@57: (< p (match-end 0)) yuuji@57: (YaTeX-match-string 1))))) yuuji@57: yuuji@58: (defun yahtml-netscape-sentinel (proc mes) yuuji@58: (cond yuuji@58: ((null (buffer-name (process-buffer proc))) yuuji@58: (set-process-buffer proc nil)) yuuji@58: ((eq (process-status proc) 'exit) yuuji@58: (let ((cb (current-buffer))) yuuji@58: (set-buffer (process-buffer proc)) yuuji@58: (goto-char (point-min)) yuuji@58: (if (search-forward "not running" nil t) yuuji@58: (progn yuuji@58: (message "Starting netscape...") yuuji@58: (start-process yuuji@58: "browser" (process-buffer proc) shell-file-name "-c" yuuji@58: (format "%s %s" yahtml-www-browser yuuji@58: (get 'yahtml-netscape-sentinel 'url))) yuuji@58: (message "Starting netscape...Done"))) yuuji@58: (set-buffer cb))))) yuuji@58: yuuji@58: (defvar yahtml-browser-process nil) yuuji@58: yuuji@58: (defun yahtml-browse-html (href) yuuji@58: "Call WWW Browser to see HREF." yuuji@58: (let ((pb "* WWW Browser *") (cb (current-buffer))) yuuji@58: (cond yuuji@58: ((string-match "[Nn]etscape" yahtml-www-browser) yuuji@58: (if (get-buffer pb) yuuji@58: (progn (set-buffer pb) (erase-buffer) (set-buffer cb))) yuuji@58: (put 'yahtml-netscape-sentinel 'url href) yuuji@58: (set-process-sentinel yuuji@58: (setq yahtml-browser-process yuuji@58: (start-process yuuji@58: "browser" pb shell-file-name "-c" yuuji@58: (format "%s -remote 'openURL(%s)'" yahtml-www-browser href))) yuuji@58: 'yahtml-netscape-sentinel)) yuuji@58: ((and (string= "w3" yahtml-www-browser) (fboundp 'w3-fetch)) yuuji@58: (w3-fetch href)) yuuji@58: ((stringp yahtml-www-browser) yuuji@58: (if (eq (process-status yahtml-browser-process) 'run) yuuji@58: (message "%s is already running" yahtml-www-browser) yuuji@58: (setq yahtml-browser-process yuuji@58: (start-process yuuji@58: "browser" "* WWW Browser *" shell-file-name yuuji@58: (format "%s %s" yahtml-www-browser href))))) yuuji@58: (t yuuji@58: (message "Sorry, jump across http is not supported."))))) yuuji@58: 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@58: (yahtml-browse-html href)) 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@58: (setq file (concat file yahtml-directory-index))) yuuji@58: (if (string-match "^/" file) yuuji@58: (setq file (yahtml-url-to-path file))) 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@58: (let ((p (point)) cmd (case-fold-search t)) yuuji@57: (save-excursion yuuji@57: (if p (goto-char p)) yuuji@58: (if (equal (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@58: (forward-list 1) yuuji@58: (error nil)) yuuji@57: (< p (point))) yuuji@57: (YaTeX-match-string 1))))) yuuji@57: yuuji@58: (defun yahtml-goto-corresponding-begend (&optional noerr) yuuji@58: "Go to corresponding opening/closing tag. yuuji@58: Optional argument NOERR causes no error for unballanced tag." yuuji@58: (let ((cmd (yahtml-on-begend-p)) m0 yuuji@58: (p (point)) (case-fold-search t) func str (nest 0)) yuuji@58: (cond yuuji@58: (cmd yuuji@58: (setq m0 (match-beginning 0)) yuuji@58: (if (= (aref cmd 0) ?/) ;on line yuuji@58: (setq cmd (substring cmd 1) yuuji@58: str (format "\\(<%s\\)\\|\\(= nest 0) (funcall func str nil t)) yuuji@58: (if (equal m0 (match-beginning 0)) yuuji@58: nil yuuji@58: (setq nest (+ nest (if (match-beginning 1) -1 1))))) yuuji@58: (if (< nest 0) yuuji@58: (goto-char (match-beginning 0)) yuuji@58: (funcall yuuji@58: (if noerr 'message 'error) yuuji@58: "Corresponding tag of `%s' not found." cmd) yuuji@58: (goto-char p) yuuji@58: nil)) yuuji@58: (t nil)))) yuuji@58: yuuji@58: (defun yahtml-current-tag () yuuji@58: "Return the current tag name." yuuji@58: (save-excursion yuuji@58: (let ((p (point)) b tag) yuuji@58: (or (bobp) yuuji@58: (looking-at "<") yuuji@58: (progn (skip-chars-backward "^<") (forward-char -1))) yuuji@58: (setq b (point)) yuuji@58: (skip-chars-forward "<") yuuji@58: (setq tag (buffer-substring yuuji@58: (point) (progn (skip-chars-forward "^ \t\n") (point)))) yuuji@58: (goto-char b) yuuji@58: (forward-list 1) yuuji@58: (and (< p (point)) tag)))) yuuji@58: yuuji@58: yuuji@58: (defun yahtml-goto-corresponding-img () yuuji@58: "View image on point" yuuji@58: (let ((tag (yahtml-current-tag)) image (p (point)) (case-fold-search t)) yuuji@58: (if (and tag yuuji@58: (string-match "img" tag) yuuji@58: (save-excursion yuuji@58: (re-search-backward "<\\s *img" nil t) yuuji@59: (re-search-forward "src=\"?\\([^\"> ]+\\)\"?") yuuji@58: (match-beginning 1) yuuji@58: (setq image yuuji@58: (buffer-substring (match-beginning 1) (match-end 1))))) yuuji@58: (progn yuuji@58: (message "Invoking %s %s..." yahtml-image-viewer image) yuuji@58: (start-process yuuji@58: "Viewer" " * Image Viewer *" shell-file-name "-c" yuuji@58: (concat yahtml-image-viewer " " image)) yuuji@58: (message "Invoking %s %s...Done" yahtml-image-viewer image))))) yuuji@57: yuuji@57: (defun yahtml-goto-corresponding-* (&optional other) yuuji@57: "Go to corresponding object." yuuji@57: (interactive) yuuji@57: (cond yuuji@57: ((yahtml-goto-corresponding-href other)) yuuji@58: ((yahtml-goto-corresponding-img)) yuuji@58: ((yahtml-goto-corresponding-begend)) yuuji@57: )) yuuji@57: yuuji@57: (defun yahtml-goto-corresponding-*-other-window () yuuji@57: "Go to corresponding object." yuuji@57: (interactive) yuuji@57: (yahtml-goto-corresponding-* t)) yuuji@57: yuuji@58: ;;; ---------- killing ---------- yuuji@58: (defun yahtml-kill-begend (&optional whole) yuuji@58: (let ((tag (yahtml-on-begend-p)) (p (make-marker)) (q (make-marker))) yuuji@58: (if tag yuuji@58: (progn yuuji@58: (or (looking-at "<") yuuji@58: (progn (skip-chars-backward "^<") (forward-char -1))) yuuji@58: (set-marker p (point)) yuuji@58: (yahtml-goto-corresponding-begend) yuuji@58: (or (looking-at "<") yuuji@58: (progn (skip-chars-backward "^<") (forward-char -1))) yuuji@58: (delete-region (point) (progn (forward-list 1) (point))) yuuji@58: (set-marker q (point)) yuuji@58: (beginning-of-line) yuuji@58: (if (looking-at "^\\s *$") yuuji@58: (delete-region (point) (progn (forward-line 1) (point)))) yuuji@58: (goto-char p) yuuji@58: (delete-region (point) (progn (forward-list 1) (point))) yuuji@58: (if (looking-at "^\\s *$") yuuji@58: (delete-region (point) (progn (forward-line 1) (point)))) yuuji@58: (if whole (delete-region p q)) yuuji@58: tag)))) yuuji@58: yuuji@58: (defun yahtml-kill-* (whole) yuuji@58: "Kill current position's HTML tag (set)." yuuji@58: (interactive "P") yuuji@58: (cond yuuji@58: ((yahtml-kill-begend whole)) yuuji@58: )) yuuji@58: yuuji@58: yuuji@58: ;;; ---------- changing ---------- yuuji@58: (defun yahtml-change-begend () yuuji@58: (let ((tag (yahtml-on-begend-p)) yuuji@58: (completion-ignore-case t) yuuji@58: (p (point)) (q (make-marker)) yuuji@58: (default (append yahtml-env-table yahtml-typeface-table)) yuuji@58: (user (append yahtml-user-env-table yahtml-user-typeface-table)) yuuji@58: (tmp (append yahtml-tmp-env-table yahtml-tmp-typeface-table)) yuuji@59: href b1 e1) yuuji@59: (cond yuuji@59: (tag yuuji@59: (cond yuuji@59: ((and (equal tag "a") yuuji@59: (save-excursion yuuji@59: (and yuuji@59: (re-search-backward "= p (point)) yuuji@59: (looking-at "href\\s *=\\s *\"?\\([^\"> \t\n]+\\)\"?") yuuji@59: (< p (match-end 0))))) yuuji@59: (setq b1 (match-beginning 1) e1 (match-end 1) yuuji@59: href (read-from-minibuffer yuuji@59: "Change href to: " "" yahtml-url-completion-map)) yuuji@59: (if (string< "" href) yuuji@59: (progn yuuji@59: (delete-region b1 e1) yuuji@59: (goto-char b1) yuuji@59: (insert href)))) yuuji@59: (t yuuji@58: (save-excursion yuuji@58: (if (= (aref tag 0) ?/) (setq tag (substring tag 1))) yuuji@58: (or (= (char-after (point)) ?<) (skip-chars-backward "^<")) yuuji@58: (skip-chars-forward "^A-Za-z") yuuji@58: (set-marker q (point)) yuuji@58: (setq p (point)) yuuji@58: (yahtml-goto-corresponding-begend) yuuji@58: (or (= (char-after (point)) ?<) yuuji@58: (skip-chars-backward "^<")) yuuji@58: (skip-chars-forward "^A-Za-z") yuuji@58: (if (= (char-after (1- (point))) ?/) yuuji@58: (progn yuuji@58: (set-marker q (point)) yuuji@58: (goto-char p))) yuuji@58: (setq tag (YaTeX-cplread-with-learning yuuji@58: (format "Change `%s' to(default %s): " yuuji@58: tag yahtml-last-begend) yuuji@58: 'default 'user 'tmp)) yuuji@58: (delete-region (point) (progn (skip-chars-forward "^>") (point))) yuuji@58: (if (string= "" tag) (setq tag yahtml-last-begend)) yuuji@58: (setq yahtml-last-begend yuuji@58: (or (cdr (assoc tag yahtml-env-table)) tag) yuuji@58: tag yahtml-last-begend) yuuji@58: (insert (format "%s%s" tag (yahtml-addin tag))) yuuji@58: (goto-char q) yuuji@58: (delete-region (point) (progn (skip-chars-forward "^>") (point))) yuuji@59: (insert tag)))))))) yuuji@58: yuuji@58: (defun yahtml-change-* () yuuji@58: "Change current position's HTML tag (set)." yuuji@58: (interactive) yuuji@58: (cond yuuji@58: ((yahtml-change-begend)) yuuji@58: )) yuuji@58: yuuji@57: ;;; ---------- commenting ---------- yuuji@57: (defun yahtml-comment-region (beg end) yuuji@57: (interactive "r") yuuji@57: (comment-region beg end nil)) yuuji@57: yuuji@57: (defun yahtml-uncomment-region (beg end) yuuji@57: (interactive "r") yuuji@57: (comment-region beg end '(4))) yuuji@57: yuuji@57: yuuji@57: yuuji@58: ;;; ---------- filling ---------- yuuji@58: (defun yahtml-fill-paragraph (arg) yuuji@58: (interactive "P") yuuji@58: (let ((case-fold-search t) (p (point))) yuuji@58: (save-excursion yuuji@58: (fill-region-as-paragraph yuuji@58: (progn (re-search-backward paragraph-start nil t) yuuji@58: (or (save-excursion yuuji@58: (goto-char (match-end 0)) yuuji@58: (if (looking-at "[ \t]*$") yuuji@58: (progn (forward-line 1) (point)))) yuuji@58: (point))) yuuji@58: (progn (goto-char p) yuuji@58: (re-search-forward paragraph-start nil t) yuuji@58: (match-beginning 0)))))) yuuji@58: yuuji@58: ;;; yuuji@58: ;;; ---------- indentation ---------- yuuji@58: ;;; yuuji@58: (defvar yahtml-hate-too-deep-indentation nil) yuuji@58: (defun yahtml-indent-line () yuuji@58: (interactive) yuuji@59: (let ((envs "[uod]l\\|table\\|t[rhd]\\|select\\|a\\b") yuuji@59: (itms "<\\(dt\\|dd\\|li\\|t[rdh]\\|option\\)>") yuuji@58: inenv p col peol (case-fold-search t)) yuuji@58: (save-excursion yuuji@58: (beginning-of-line) yuuji@58: (setq inenv (or (YaTeX-inner-environment) "html") yuuji@58: col (get 'YaTeX-inner-environment 'indent) yuuji@58: p (get 'YaTeX-inner-environment 'point) yuuji@58: op)) yuuji@58: (save-excursion yuuji@58: (cond yuuji@58: ((string-match envs inenv) yuuji@58: (save-excursion yuuji@58: (beginning-of-line) yuuji@58: (skip-chars-forward " \t") yuuji@58: (cond yuuji@58: ((looking-at (concat "")) yuuji@58: (YaTeX-reindent col)) yuuji@58: ((or (looking-at itms) yuuji@58: (and yahtml-hate-too-deep-indentation yuuji@58: (looking-at (concat "<" envs)))) yuuji@58: (YaTeX-reindent (+ col YaTeX-environment-indent))) yuuji@58: ((and (< p (point)) yuuji@58: (save-excursion yuuji@58: (and yuuji@58: ;;(re-search-backward itms p t) yuuji@58: (setq op (point)) yuuji@58: (goto-char p) yuuji@58: (re-search-forward itms op t) yuuji@58: (goto-char (match-end 0)) yuuji@58: (skip-chars-forward " \t") yuuji@58: (setq col (current-column))))) yuuji@58: (YaTeX-reindent col)) yuuji@58: (t yuuji@58: (YaTeX-reindent (+ col YaTeX-environment-indent))))))) yuuji@58: (and (bolp) (skip-chars-forward " \t")) yuuji@58: (if (and (setq inenv (yahtml-on-begend-p)) yuuji@58: (string-match (concat "^\\(" envs "\\)") inenv)) yuuji@58: (save-excursion yuuji@58: (setq peol (point-end-of-line)) yuuji@58: (or (= (char-after (point)) ?<) yuuji@58: (progn (skip-chars-backward "^<") (forward-char -1))) yuuji@58: (setq col (current-column)) yuuji@58: (if (and (yahtml-goto-corresponding-begend t) yuuji@58: (> (point) peol)) ;if on the different line yuuji@58: (YaTeX-reindent col))))) yuuji@58: (and (bolp) (skip-chars-forward " \t")))) yuuji@58: yuuji@58: ;(defun yahtml-fill-item () yuuji@58: ; "Fill item HTML version" yuuji@58: ; (interactive) yuuji@58: ; (let (inenv p fill-prefix peol (case-fold-search t)) yuuji@58: ; (setq inenv (or (YaTeX-inner-environment) "html") yuuji@58: ; p (get 'YaTeX-inner-environment 'point)) yuuji@58: ; (cond yuuji@58: ; ((string-match "^[uod]l" inenv) yuuji@58: ; (save-excursion yuuji@58: ; (if (re-search-backward "<\\(d[td]\\|li\\)>[ \t\n]*" p t) yuuji@58: ; (progn yuuji@58: ; (goto-char (match-end 0)) yuuji@58: ; (setq col (current-column))) yuuji@58: ; (error "No
  • ,
    ,
    "))) yuuji@58: ; (save-excursion yuuji@58: ; (end-of-line) yuuji@58: ; (setq peol (point)) yuuji@58: ; (newline) yuuji@58: ; (indent-to-column col) yuuji@58: ; (setq fill-prefix (buffer-substring (point) (1+ peol))) yuuji@58: ; (delete-region (point) peol) yuuji@58: ; (fill-region-as-paragraph yuuji@58: ; (progn (re-search-backward paragraph-start nil t) (point)) yuuji@58: ; (progn (re-search-forward paragraph-start nil t 2) yuuji@58: ; (match-beginning 0))))) yuuji@58: ; (t nil)))) yuuji@58: yuuji@58: ;;; yuuji@58: ;;; ---------- Browsing ---------- yuuji@58: ;;; yuuji@58: (defun yahtml-browse-menu () yuuji@58: "Browsing menu" yuuji@58: (interactive) yuuji@58: (message "B)rowse R)eload...") yuuji@58: (let ((c (char-to-string (read-char)))) yuuji@58: (cond yuuji@58: ((string-match "[bj]" c) yuuji@58: (yahtml-browse-current-file)) yuuji@58: ((string-match "r" c) yuuji@58: (yahtml-browse-reload))))) yuuji@58: yuuji@58: (defun yahtml-file-to-url (file) yuuji@58: "Convert local unix file name to URL. yuuji@58: If no matches found in yahtml-path-url-alist, return raw file name." yuuji@58: (let ((list yahtml-path-url-alist) p url) yuuji@58: (if (file-directory-p file) yuuji@58: (setq file (expand-file-name yahtml-directory-index file)) yuuji@58: (setq file (expand-file-name file))) yuuji@58: (while list yuuji@58: (if (string-match (concat "^" (regexp-quote (car (car list)))) file) yuuji@58: (setq url (cdr (car list)) yuuji@58: file (substring file (match-end 0)) yuuji@58: url (concat url file) yuuji@58: list nil)) yuuji@58: (setq list (cdr list))) yuuji@58: (or url (concat "file:" file)))) yuuji@58: yuuji@58: (defun yahtml-url-to-path (file &optional basedir) yuuji@58: "Convert local URL name to unix file name." yuuji@58: (let ((list yahtml-path-url-alist) url realpath docroot yuuji@58: (dirsufp (string-match "/$" file))) yuuji@58: (setq basedir (or basedir yuuji@58: (file-name-directory yuuji@58: (expand-file-name default-directory)))) yuuji@58: (cond yuuji@58: ((string-match "^/" file) yuuji@58: (while list yuuji@59: (if (file-directory-p (car (car list))) yuuji@58: (progn yuuji@58: (setq url (cdr (car list))) yuuji@58: (if (string-match "\\(http://[^/]*\\)/" url) yuuji@58: (setq docroot (substring url (match-end 1))) yuuji@58: (setq docroot url)) yuuji@59: (if (string-match (concat "^" (regexp-quote docroot)) file) yuuji@58: (setq realpath yuuji@58: (expand-file-name yuuji@58: (substring yuuji@59: file yuuji@59: (if (= (aref file (1- (match-end 0))) ?/) yuuji@59: (match-end 0) ; "/foo" yuuji@59: (min (1+ (match-end 0)) (length file)))) ; "/~foo" yuuji@58: (car (car list))))) yuuji@58: (if realpath yuuji@58: (progn (setq list nil) yuuji@58: (if (and dirsufp (not (string-match "/$" realpath))) yuuji@58: (setq realpath (concat realpath "/"))))))) yuuji@58: (setq list (cdr list))) yuuji@58: realpath) yuuji@58: (t file)))) yuuji@58: yuuji@58: (defun yahtml-browse-current-file () yuuji@58: "Call WWW browser on current file." yuuji@58: (interactive) yuuji@58: (basic-save-buffer) yuuji@58: (yahtml-browse-html (yahtml-file-to-url (buffer-file-name)))) yuuji@58: yuuji@58: (defun yahtml-browse-reload () yuuji@58: "Send `reload' event to netzscape." yuuji@58: (let ((pb "* WWW Browser *") (cb (current-buffer))) yuuji@58: (cond yuuji@58: ((string-match "[Nn]etscape" yahtml-www-browser) yuuji@58: (if (get-buffer pb) yuuji@58: (progn (set-buffer pb) (erase-buffer) (set-buffer cb))) yuuji@58: ;;(or (get 'yahtml-netscape-sentinel 'url) yuuji@58: ;; (error "Reload should be called after Browsing.")) yuuji@58: (put 'yahtml-netscape-sentinel 'url yuuji@58: (yahtml-file-to-url (buffer-file-name))) yuuji@58: (basic-save-buffer) yuuji@58: (set-process-sentinel yuuji@58: (setq yahtml-browser-process yuuji@58: (start-process yuuji@58: "browser" pb shell-file-name "-c" yuuji@58: (format "%s -remote 'reload'" yahtml-www-browser))) yuuji@58: 'yahtml-netscape-sentinel)) yuuji@58: (t yuuji@58: (message "Sorry, RELOAD is supported only for Netscape."))))) yuuji@58: yuuji@58: ;;; ---------- Intelligent newline ---------- yuuji@58: (defun yahtml-intelligent-newline (arg) yuuji@58: "Intelligent newline for HTML" yuuji@58: (interactive "P") yuuji@58: (let ((env (downcase (or (YaTeX-inner-environment) "html"))) func) yuuji@58: (setq func (intern-soft (concat "yahtml-intelligent-newline-" env))) yuuji@58: (end-of-line) yuuji@58: (newline) yuuji@58: (if (and env func (fboundp func)) yuuji@58: (funcall func)))) yuuji@58: yuuji@58: (defun yahtml-intelligent-newline-ul () yuuji@58: (interactive) yuuji@58: (insert (if yahtml-prefer-upcases "
  • " "
  • ")) yuuji@58: (yahtml-indent-line)) yuuji@58: yuuji@58: (fset 'yahtml-intelligent-newline-ol 'yahtml-intelligent-newline-ul) yuuji@58: yuuji@58: (defun yahtml-intelligent-newline-dl () yuuji@58: (interactive) yuuji@58: (let ((case-fold-search t)) yuuji@58: (if (save-excursion yuuji@58: (re-search-backward "<\\(\\(dt\\)\\|\\(dd\\)\\)>" yuuji@58: (get 'YaTeX-inner-environment 'point) t)) yuuji@58: (cond yuuji@58: ((match-beginning 2) yuuji@58: (insert (if yahtml-prefer-upcases "
    " "
    ")) yuuji@58: (setq yahtml-last-single-cmd "dt")) yuuji@58: ((match-beginning 3) yuuji@58: (insert (if yahtml-prefer-upcases "
    " "
    ")) yuuji@58: (setq yahtml-last-single-cmd "dd"))) yuuji@58: (insert (if yahtml-prefer-upcases "
    " "
    "))) yuuji@58: (yahtml-indent-line))) yuuji@58: yuuji@59: (defun yahtml-intelligent-newline-select () yuuji@59: (interactive) yuuji@59: (insert "<" (if yahtml-prefer-upcases "OPTION" "option") "> ") yuuji@59: (yahtml-indent-line)) yuuji@59: yuuji@58: ;;; ---------- Marking ---------- yuuji@58: (defun yahtml-mark-begend () yuuji@58: "Mark current tag" yuuji@58: (interactive) yuuji@58: (YaTeX-beginning-of-environment) yuuji@58: (let ((p (point))) yuuji@58: (save-excursion yuuji@58: (skip-chars-backward " \t" (point-beginning-of-line)) yuuji@58: (if (bolp) (setq p (point)))) yuuji@58: (push-mark p t)) yuuji@58: (yahtml-goto-corresponding-begend) yuuji@58: (forward-list 1) yuuji@58: (if (eolp) (forward-char 1))) yuuji@58: yuuji@59: ;;; ---------- complete marks ---------- yuuji@59: (defun yahtml-complete-mark () yuuji@59: "Complete >, <, &asterisk, and "e." yuuji@59: (interactive) yuuji@59: (message "1:< 2:> 3:& 4:\"") yuuji@59: (let ((c (read-char))) yuuji@59: (setq c (if (or (< c ?0) (> c ?5)) yuuji@59: (string-match (regexp-quote (char-to-string c)) "<>&\"") yuuji@59: (- c ?1))) yuuji@59: (if (or (< c 0) (> c 4)) yuuji@59: nil yuuji@59: (insert (format "&%s;" (nth c '("lt" "gt" "amp" "quot"))))))) yuuji@59: yuuji@59: yuuji@57: ;;; ---------- ---------- yuuji@57: ;;; ---------- ---------- yuuji@57: yuuji@57: ;;; yuuji@57: ;;hilit19 yuuji@57: ;;; yuuji@57: (defvar yahtml-default-face-table yuuji@57: '( yuuji@57: (form black/ivory white/hex-442233 italic) yuuji@57: )) yuuji@57: (defvar yahtml-hilit-patterns-alist yuuji@57: '( yuuji@57: ;; comments yuuji@57: ("" 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@58: (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: