を入力します。
;;; * menu-bar yahtml 選択したアイテムをメニューより補完できます。
;;; (私はメニューが嫌いなんですが、htmlに関してはメ
;;; ニューは一番ありがたいかも)
;;; * [prefix] g 対応するタグ、 <->
や href="xxx" の
;;; ような TAG にジャンプします。
;;; の場合はイメージビューワを呼び出
;;; します。href=hoge.html の場合はhoge.htmlに飛びま
;;; す。
;;; * [prefix] k ポイント上の HTML タグを消去します。
;;; もし universal-argument を付けた場合(C-uを先に押
;;; す)HTMLタグで囲まれた内容も同時に消去します。
;;; * [prefix] c ポイント上のタグを変更します。
;;; `href="xxx"'の上で [prefix] c を利用した場合は、
;;; 参照しているリンクを補完機能を使いながら変更で
;;; きます。
;;; * [prefix] t j カレントファイルに対して jweblint を呼び出しま
;;; す。ファイル先頭付近に
;;;
;;; と書いておくとそのコマンドを呼びます。
;;; * [prefix] t p WWW ブラウザでカレントファイルを表示します。
;;; (lisp変数 yahtml-www-browser の設定をお忘れな
;;; く。お推めは "firefox" です)
;;; * [prefix] a YaTeX のアクセント記号補完と同じです。
;;; < > 等が入力できます。
;;; * [prefix] ; 指定したリジョン中の > < & " をそれぞれ
;;; > < & " に変換します。
;;; * [prefix] : 指定したリジョン中で上と逆の変換をします。
;;; * [prefix] # 指定したリジョン中で%エンコードの必要な文字が
;;; あればそれらをエンコードします。
;;; * [prefix] } リジョン内の特定文字区切りのレコードを 並びに
;;; 変換します。C-u (universal-argument) 付きで起動
;;; するとtd以外の任意要素で括ります。thdを指定する
;;; と最初の1つだけth,残りすべてをtdで括ります。
;;; * [prefix] ] リジョン内のすべての行をフィールドごとにtdで括り,
;;; さらに各行をtrで括ります。universal-argument を
;;; 付けるとフィールド括りをtd以外に指定できます。
;;; * [prefix] ESC yahtml-mode を抜け yahtml-mode に入る前に動作し
;;; ていたメジャーモードに戻ります。
;;;
;;; [謝辞]
;;;
;;; fj野鳥の会の皆さんには貴重な助言を頂きました。また、下に示す方々には
;;; 特に大きな協力を頂きました。あわせてここに感謝申し上げます。
;;;
;;; * 横田和也さん(マツダ)
;;; マニュアルの和訳をして頂きました。
;;; * 吉田尚志さん(NTT Data)
;;; Mule for Win32 での動作のさせ方を教えて頂きました。
;;; (というかほとんどやってもらった ^^;)
;;;
;;; Code:
(require 'yatexlib)
;;; --- customizable variable starts here ---
(defvar yahtml-prefix "\C-c"
"*Prefix key stroke of yahtml functions.")
(defvar yahtml-image-viewer "display" "*Image viewer program")
(defvar yahtml-www-browser "firefox" "*WWW Browser command")
(defvar yahtml-kanji-code 4
"*Kanji coding system number of html file; 1=sjis, 2=jis, 3=euc, 4=UTF-8")
;;(defvar yahtml-coding-system
;; (cdr (assq yahtml-kanji-code YaTeX-kanji-code-alist))
;; "Kanji coding system")
(and (featurep 'mule)
(integerp yahtml-kanji-code)
(setq yahtml-kanji-code
(cdr (assq yahtml-kanji-code YaTeX-kanji-code-alist))))
(defvar yahtml-fill-column 72 "*fill culumn used for yahtml-mode")
(defvar yahtml-fill-prefix nil "*fill prefix for yahtml-mode")
;;(defvar yahtml-www-server "www" "*Host name of your domain's WWW server")
(defvar yahtml-path-url-alist nil
"*Alist of unix path name vs. URL name of WWW server.
Ex.
'((\"/usr/home/yuuji/http\" . \"http://www.comp.ae.keio.ac.jp/~yuuji\")
(\"/home/yuuji/http\" . \"http://www.gentei.org/~yuuji\"))")
(defvar yahtml-directory-index "index.html"
"*Directory index file name;
Consult your site's WWW administrator.")
(defvar yahtml-environment-indent 1
"*Indentation depth of HTML's listing environment")
;; YaTeX-japan is defined in yatexlib.el
(defvar yahtml-lint-program (if YaTeX-japan "jweblint" "weblint")
"*Program name to lint HTML file")
(defvar yahtml-hate-too-deep-indentation nil
"*Non-nil for this variable suppress deep indentation in listing environments.")
(defvar yahtml-always-/p t
"*Those who always use with set this to t.")
(defvar yahtml-always-/li nil
"*Those who always use with set this to t.")
(defvar yahtml-always-/dt nil
"*Those who always use with set this to t.")
(defvar yahtml-always-/dd nil
"*Those who always use with set this to t.")
(defvar yahtml-p-prefered-env-regexp "^\\(body\\|dl\\|blockquote\\)"
"*Regexp of envs where paragraphed sentences are prefered.")
(defvar yahtml-template-file "~/public_html/template.html"
"*Template HTML file. It'll be inserted to empty file.")
(defvar yahtml-prefer-upcases nil
"*Non-nil for preferring upcase TAGs")
(defvar yahtml-prefer-upcase-attributes nil
"*Non-nil for preferring upcase attributes")
(defvar yahtml-server-type 'apache "*WWW server program type")
(defvar yahtml-apache-access-file ".htaccess"
"*Server access file name for apache")
(defvar yahtml-use-css t "*Use stylesheet or not")
(defvar yahtml-image-inspection-bytes 500000
"*Number of bytes to inspect the image for geometry information")
(defvar yahtml:img-default-alt-format "%xx%y(%sbytes)"
"*Default format of img entity's ALT attributes.
%x: width, %y: height, %s: size in bytes, %c: first comment string,
%f: filename")
(defvar yahtml-faithful-to-htmllint yahtml-always-/li
"*Non-nil doesn't put space after opening tags.")
(defvar yahtml-error-line-regexp
"^\\(.*\\)(\\([0-9]+\\)):\\|^line \\([0-9]+\\)"
"*Regexp of error position which is produced by lint program.")
(defvar yahtml-translate-hyphens-when-comment-region t
"*Non-nil for translate hyphens to - when comment-region")
(defvar yahtml-escape-chars 'ask
"*Escape reserved characters to URL-encoding or not.
Nil for never, t for everytime, and 'ask for inquiring
at each reserved chars.")
(defvar yahtml-use-font-lock (and (featurep 'font-lock)
(fboundp 'font-lock-fontify-region))
"*Non-nil means to use font-lock to fontify buffer.")
(defvar yahtml-use-hilit19 (and (featurep 'hilit19)
(not yahtml-use-font-lock))
"*Non-nil means to Use hilit19 to highlight buffer")
(defvar yahtml-mode-abbrev-table nil
"*Abbrev table in use in yahtml-mode buffers.")
(define-abbrev-table 'yahtml-mode-abbrev-table ())
(defvar yahtml-indentation-boundary "^\\s *"
"*Boundary regexp for indentation calculation.")
(defvar yahtml-html4-strict t
"*Non-nil means editing HTML 4.01 Strict.
Completing read for obsoleted attributes disabled.")
(defvar yahtml-electric-indent-mode -1
"*(Emacs 24.4+) Pass this value to electric-indent-local-mode.
-1 means `off'.")
;;; --- customizable variable ends here ---
(defvar yahtml-prefix-map nil)
(defvar yahtml-mode-map nil "Keymap used in yahtml-mode.")
(defvar yahtml-lint-buffer-map nil "Keymap used in lint buffer.")
(defvar yahtml-shell-command-option
(or (and (boundp 'shell-command-option) shell-command-option)
(if (eq system-type 'ms-dos) "/c" "-c")))
(defvar yahtml-use-highlighting (or yahtml-use-font-lock yahtml-use-hilit19))
(defun yahtml-define-begend-key-normal (key env &optional map)
"Define short cut yahtml-insert-begend key."
(YaTeX-define-key
key
(list 'lambda '(arg) '(interactive "P")
(list 'yahtml-insert-begend 'arg env))
map))
(defun yahtml-define-begend-region-key (key env &optional map)
"Define short cut yahtml-insert-begend-region key."
(YaTeX-define-key key (list 'lambda nil '(interactive)
(list 'yahtml-insert-begend t env)) map))
(defun yahtml-define-begend-key (key env &optional map)
"Define short cut key for begin type completion both for
normal and region mode. To customize yahtml, user should use this function."
(yahtml-define-begend-key-normal key env map)
(if YaTeX-inhibit-prefix-letter nil
(yahtml-define-begend-region-key
(concat (upcase (substring key 0 1)) (substring key 1)) env map)))
(if yahtml-mode-map nil
(setq yahtml-mode-map (make-sparse-keymap)
yahtml-prefix-map (make-sparse-keymap))
(define-key yahtml-mode-map yahtml-prefix yahtml-prefix-map)
(define-key yahtml-mode-map "\M-\C-@" 'yahtml-mark-begend)
(if (and (boundp 'window-system) (eq window-system 'x) YaTeX-emacs-19)
(define-key yahtml-mode-map [?\M-\C- ] 'yahtml-mark-begend))
(define-key yahtml-mode-map "\M-\C-a" 'YaTeX-beginning-of-environment)
(define-key yahtml-mode-map "\M-\C-e" 'YaTeX-end-of-environment)
(define-key yahtml-mode-map "\M-\C-m" 'yahtml-intelligent-newline)
(define-key yahtml-mode-map "\M-\C-j" 'yahtml-intelligent-newline)
(define-key yahtml-mode-map "\C-i" 'yahtml-indent-line)
(define-key yahtml-mode-map "&" 'yahtml-insert-amps)
(let ((map yahtml-prefix-map))
(YaTeX-define-key "^" 'yahtml-visit-main map)
(YaTeX-define-key "4^" 'yahtml-visit-main-other-window map)
(YaTeX-define-key "4g" 'yahtml-goto-corresponding-*-other-window map)
(YaTeX-define-key "44" 'YaTeX-switch-to-window map)
(and YaTeX-emacs-19 window-system
(progn
(YaTeX-define-key "5^" 'yahtml-visit-main-other-frame map)
(YaTeX-define-key "5g" 'yahtml-goto-corresponding-*-other-frame map)
(YaTeX-define-key "55" 'YaTeX-switch-to-window map)))
(YaTeX-define-key "v" 'yahtml-version map)
(YaTeX-define-key "s" 'yahtml-insert-form map)
(YaTeX-define-key "l" 'yahtml-insert-tag map)
(YaTeX-define-key "L" 'yahtml-insert-tag-region map)
(YaTeX-define-key "m" 'yahtml-insert-single map)
(YaTeX-define-key "n" (function(lambda () (interactive) (insert (if yahtml-prefer-upcases " " " ")))) map)
(YaTeX-define-key "-" (function(lambda () (interactive) (insert (if yahtml-prefer-upcases " " " ") "\n"))) map)
(YaTeX-define-key "p" 'yahtml-insert-p map)
(if YaTeX-no-begend-shortcut
(progn
(YaTeX-define-key "B" 'yahtml-insert-begend-region map)
(YaTeX-define-key "b" 'yahtml-insert-begend map))
(yahtml-define-begend-key "bh" "html" map)
(yahtml-define-begend-key "bH" "head" map)
(yahtml-define-begend-key "bt" "title" map)
(yahtml-define-begend-key "bT" "table" map)
(yahtml-define-begend-key "bb" "body" map)
(yahtml-define-begend-key "bc" "center" map)
(yahtml-define-begend-key "bd" "dl" map)
(yahtml-define-begend-key "bD" "div" map)
(yahtml-define-begend-key "bu" "ul" map)
(yahtml-define-begend-key "bo" "ol" map)
(yahtml-define-begend-key "b1" "h1" map)
(yahtml-define-begend-key "b2" "h2" map)
(yahtml-define-begend-key "b3" "h3" map)
(yahtml-define-begend-key "ba" "a" map)
(yahtml-define-begend-key "bf" "form" map)
(yahtml-define-begend-key "bl" "label" map)
(yahtml-define-begend-key "bs" "select" map)
(yahtml-define-begend-key "bv" "div" map)
(yahtml-define-begend-key "bS" "span" map)
(yahtml-define-begend-key "bp" "pre" map)
(yahtml-define-begend-key "bq" "blockquote" map)
(YaTeX-define-key "b " 'yahtml-insert-begend map)
(YaTeX-define-key "B " 'yahtml-insert-begend-region map))
(YaTeX-define-key "e" 'YaTeX-end-environment map)
(YaTeX-define-key ">" 'yahtml-comment-region map)
(YaTeX-define-key "<" 'yahtml-uncomment-region map)
(YaTeX-define-key "g" 'yahtml-goto-corresponding-* map)
(YaTeX-define-key "k" 'yahtml-kill-* map)
(YaTeX-define-key "c" 'yahtml-change-* map)
(YaTeX-define-key "t" 'yahtml-browse-menu map)
(YaTeX-define-key "a" 'yahtml-char-entity-ref map)
(YaTeX-define-key "'" 'yahtml-prev-error map)
(YaTeX-define-key ";" 'yahtml-translate-region map)
(YaTeX-define-key ":" 'yahtml-translate-reverse-region map)
(YaTeX-define-key "#" 'yahtml-escape-chars-region map)
(YaTeX-define-key "}" 'yahtml-td-region map)
(YaTeX-define-key "]" 'yahtml-tr-region map)
;;;;;(YaTeX-define-key "i" 'yahtml-fill-item map)
(YaTeX-define-key "\e" 'yahtml-quit map))
(substitute-all-key-definition
'fill-paragraph 'yahtml-fill-paragraph yahtml-mode-map)
(substitute-all-key-definition
'kill-buffer 'YaTeX-kill-buffer yahtml-mode-map))
(if yahtml-lint-buffer-map nil
(setq yahtml-lint-buffer-map (make-keymap))
(define-key yahtml-lint-buffer-map " " 'yahtml-jump-to-error-line))
(defvar yahtml-paragraph-start
(concat
"^$\\|")
(comment-start-skip . comment-start)
(indent-line-function . yahtml-indent-line)))
(if yahtml-use-font-lock
(progn
(yahtml-font-lock-set-default-keywords)
(or (featurep 'xemacs)
(progn
(set (make-local-variable 'font-lock-defaults)
'(yahtml-font-lock-keywords nil t))
;;(font-lock-mode -1)
(font-lock-mode 1) ;;Why should I fontify again???
;; in yatex-mode, there's no need to refontify...
(font-lock-fontify-buffer)))))
;; +dnd for X11 w/ emacs23+
(and window-system (featurep 'dnd)
(set (make-local-variable 'dnd-protocol-alist)
(cons (cons "^\\(file\\|https?\\):" 'yahtml-dnd-handler)
dnd-protocol-alist)))
(set-syntax-table yahtml-syntax-table)
(use-local-map yahtml-mode-map)
(YaTeX-read-user-completion-table)
(yahtml-css-scan-styles)
;(turn-on-auto-fill) ;Sorry, this is prerequisite
(and (= 0 (buffer-size)) (file-exists-p yahtml-template-file)
(y-or-n-p (format "Insert %s?" yahtml-template-file))
(insert-file-contents (expand-file-name yahtml-template-file)))
(if (fboundp 'electric-indent-local-mode)
(electric-indent-local-mode yahtml-electric-indent-mode))
(run-hooks 'text-mode-hook 'yahtml-mode-hook)
;; This warning should be removed after a while(2000/12/2)
(let ((fld (or (and (local-variable-p 'font-lock-defaults (current-buffer))
font-lock-defaults)
(get 'yahtml-mode 'font-lock-defaults))))
(and fld (not (memq 'yahtml-font-lock-keywords fld))
(YaTeX-warning-font-lock "yahtml"))))
(defun yahtml-version ()
"Return string of the version of running yahtml."
(interactive)
(message
(concat "Yet Another HTML-mode "
(if YaTeX-japan "「HTML屋」" "`yahtml'")
" Revision "
yahtml-revision-number)))
(defun yahtml-quit ()
(interactive)
(and yahtml-mode-old-mode
(fboundp yahtml-mode-old-mode)
(funcall yahtml-mode-old-mode)))
(defun yahtml-define-menu (keymap bindlist)
(cond
((featurep 'xemacs)
(let ((name (keymap-name (symbol-value keymap))))
(set keymap nil)
(mapcar
(function
(lambda (bind)
(setq bind (cdr bind))
(if (eq (car (cdr bind)) 'lambda)
(setcar (cdr bind) 'progn))
(if (stringp (car (cdr bind)))
(set keymap (cons (cdr bind) (symbol-value keymap)))
(set keymap (cons (vector (car bind) (cdr bind) t)
(symbol-value keymap))))))
bindlist)
(set keymap (cons name (symbol-value keymap)))))
(t
(mapcar
(function
(lambda (bind)
(define-key (symbol-value keymap) (vector (car bind)) (cdr bind))))
bindlist))))
(defvar yahtml-menu-map nil "Menu map of yahtml")
(defvar yahtml-menu-map-sectioning nil "Menu map of yahtml(sectioning)")
(defvar yahtml-menu-map-listing nil "Menu map of yahtml(listing)")
(defvar yahtml-menu-map-logical nil "Menu map of yahtml(logical tags)")
(defvar yahtml-menu-map-typeface nil "Menu map of yahtml(typeface tags)")
;;; Variables for mosaic url history
(defvar yahtml-urls nil "Alist of global history")
(defvar yahtml-urls-private nil)
(defvar yahtml-urls-local nil)
(cond
((and YaTeX-emacs-19 (null yahtml-menu-map))
(setq yahtml-menu-map (make-sparse-keymap "yahtml"))
(setq yahtml-menu-map-sectioning (make-sparse-keymap "sectioning menu"))
(YaTeX-define-menu
'yahtml-menu-map-sectioning
(nreverse
'((1 "H1" . (lambda () (interactive) (yahtml-insert-begend nil "H1")))
(2 "H2" . (lambda () (interactive) (yahtml-insert-begend nil "H2")))
(3 "H3" . (lambda () (interactive) (yahtml-insert-begend nil "H3")))
(4 "H4" . (lambda () (interactive) (yahtml-insert-begend nil "H4")))
(5 "H5" . (lambda () (interactive) (yahtml-insert-begend nil "H5")))
(6 "H6" . (lambda () (interactive) (yahtml-insert-begend nil "H6")))
)))
(setq yahtml-menu-map-logical (make-sparse-keymap "logical tags"))
(YaTeX-define-menu
'yahtml-menu-map-logical
(nreverse
'((em "Embolden" .
(lambda () (interactive) (yahtml-insert-tag nil "EM")))
(dfn "Define a word" .
(lambda () (interactive) (yahtml-insert-tag nil "DFN")))
(cite "Citation" .
(lambda () (interactive) (yahtml-insert-tag nil "CITE")))
(code "Code" .
(lambda () (interactive) (yahtml-insert-tag nil "CODE")))
(kbd "Keyboard" .
(lambda () (interactive) (yahtml-insert-tag nil "KBD")))
(samp "Sample display" .
(lambda () (interactive) (yahtml-insert-tag nil "SAMP")))
(strong "Strong" .
(lambda () (interactive) (yahtml-insert-tag nil "STRONG")))
(VAR "Variable notation" .
(lambda () (interactive) (yahtml-insert-tag nil "var"))))))
(setq yahtml-menu-map-typeface (make-sparse-keymap "typeface tags"))
(YaTeX-define-menu
'yahtml-menu-map-typeface
(nreverse
'((b "Bold" .
(lambda () (interactive) (yahtml-insert-tag nil "b")))
(i "Italic" .
(lambda () (interactive) (yahtml-insert-tag nil "i")))
(tt "Typewriter" .
(lambda () (interactive) (yahtml-insert-tag nil "tt")))
(u "Underlined" .
(lambda () (interactive) (yahtml-insert-tag nil "u"))))))
(setq yahtml-menu-map-listing (make-sparse-keymap "listing"))
(YaTeX-define-menu
'yahtml-menu-map-listing
(nreverse
'((ul "Unordered" .
(lambda () (interactive) (yahtml-insert-begend nil "ul")))
(ol "Ordered" .
(lambda () (interactive) (yahtml-insert-begend nil "ol")))
(dl "Definition" .
(lambda () (interactive) (yahtml-insert-begend nil "dl"))))))
(setq yahtml-menu-map-item (make-sparse-keymap "item"))
(YaTeX-define-menu
'yahtml-menu-map-item
(nreverse
'((li "Simple item" .
(lambda () (interactive) (yahtml-insert-single "li")))
(dt "Define term" .
(lambda () (interactive) (yahtml-insert-single "dt")))
(dd "Description of term" .
(lambda () (interactive) (yahtml-insert-single "dd"))))))
(define-key yahtml-mode-map [menu-bar yahtml]
(cons "yahtml" yahtml-menu-map))
(YaTeX-define-menu
'yahtml-menu-map
(nreverse
(list
(cons (list 'sect "Sectioning")
(cons "sectioning" yahtml-menu-map-sectioning))
(cons (list 'list "Listing")
(cons "Listing" yahtml-menu-map-listing))
(cons (list 'item "Item")
(cons "Itemizing" yahtml-menu-map-item));;;
(cons (list 'logi "Logical tags")
(cons "logical" yahtml-menu-map-logical))
(cons (list 'type "Typeface tags")
(cons "typeface" yahtml-menu-map-typeface)))))
(if (featurep 'xemacs)
(add-hook 'yahtml-mode-hook
(function
(lambda ()
(or (assoc "yahtml" current-menubar)
(progn
(set-buffer-menubar (copy-sequence current-menubar))
(add-submenu nil yahtml-menu-map)))))))))
;;; ----------- Completion ----------
(defvar yahtml-last-begend "html")
(defun yahtml-insert-begend (&optional region env)
"Insert ... ."
(interactive "P")
(setq yahtml-current-completion-type 'multiline
region (or region (YaTeX-region-active-p)))
(let*((completion-ignore-case t)
(cmd
(or env
(YaTeX-cplread-with-learning
(format "Environment(default %s): " yahtml-last-begend)
'yahtml-env-table 'yahtml-user-env-table 'yahtml-tmp-env-table)))
(bolp (save-excursion
(skip-chars-backward " \t" (point-beginning-of-line)) (bolp)))
(cc (current-column)))
(if (string< "" cmd) (setq yahtml-last-begend cmd))
(setq yahtml-last-begend
(or (cdr (assoc yahtml-last-begend yahtml-env-table))
yahtml-last-begend))
(setq cmd yahtml-last-begend)
(setq cmd (funcall (if yahtml-prefer-upcases 'upcase 'downcase) cmd))
(if region
;; We want to keep region effective for new tagged environment
;; to enable continuous regioning by another environment
(let ((beg (region-beginning))
(end (region-end))
(addin (yahtml-addin cmd)))
(save-excursion
(goto-char end)
(insert-before-markers (format "%s>%s" cmd (if bolp "\n" "")))
(goto-char beg)
(insert (format "<%s%s>%s" cmd addin (if bolp "\n" "")))))
(insert (format "<%s%s>" cmd (yahtml-addin cmd)))
(save-excursion
(insert "\n")
(indent-to-column cc)
(insert (format "%s>" cmd)))
(if (string-match "^[ap]$" cmd) ;aとp決め打ちってのが美しくない…
(newline)
(yahtml-intelligent-newline nil))
(yahtml-indent-line))))
(defun yahtml-insert-begend-region ()
"Call yahtml-insert-begend in the region mode."
(interactive)
(yahtml-insert-begend t))
(defun yahtml-insert-form (&optional form)
"Insert |