yatex

diff yahtml.el @ 59:48ac97a6b6ce

Call drawing tools ID completion (yahtml)
author yuuji
date Wed, 01 May 1996 15:35:40 +0000
parents 3a7c0c2bf16d
children 9e08ed569d80
line diff
     1.1 --- a/yahtml.el	Thu Feb 01 18:55:47 1996 +0000
     1.2 +++ b/yahtml.el	Wed May 01 15:35:40 1996 +0000
     1.3 @@ -1,6 +1,6 @@
     1.4  ;;; -*- Emacs-Lisp -*-
     1.5  ;;; (c ) 1994 by HIROSE Yuuji [yuuji@ae.keio.ac.jp, pcs39334@asciinet.or.jp]
     1.6 -;;; Last modified Fri Feb  2 02:37:23 1996 on supra
     1.7 +;;; Last modified Tue Apr 23 23:13:12 1996 on inspire
     1.8  ;;; This package is no longer tentative.
     1.9  ;;; $Id$
    1.10  
    1.11 @@ -28,6 +28,8 @@
    1.12  ;;;			normally requires closing tag `</H1>
    1.13  ;;;			<a href=foo> ... </a> is also classified into
    1.14  ;;;			this group
    1.15 +;;;			When input `href=...', you can complete file
    1.16 +;;;			name or label(href="#foo") by typing TAB.
    1.17  ;;;  * [prefix] s	Complete declarative notations such as
    1.18  ;;;			`<img src="foo.gif">'
    1.19  ;;;			`<input name="var" ...>'
    1.20 @@ -35,20 +37,26 @@
    1.21  ;;;			`<i> ... </i>' or `<samp> ... </samp>'
    1.22  ;;;  * [prefix] m	Complete single commands such as
    1.23  ;;;			`<br>' or `<hr> or <li>...'
    1.24 +;;;  * M-RET		Intelligent newline; if current TAG is one of
    1.25 +;;;			ul, ol, or  dl. insert newline and <li> or
    1.26 +;;;			<dt> or <dd> suitable for current condition.
    1.27  ;;;  * menu-bar yahtml	Complete all by selecting a menu item (Though I
    1.28  ;;;			hate menu, this is most useful)
    1.29  ;;;  * [prefix] g	Goto corresponding Tag or HREF such as
    1.30 -;;; 			<dl> <-> </dl>  or href="xxx"
    1.31 +;;; 			<dl> <-> </dl>  or href="xxx".
    1.32 +;;;			Or invoke image viewer if point is on <img src=...>.
    1.33  ;;;  * [prefix] k	Kill html tags on the point.  If you provide
    1.34  ;;; 			universal-argument, kill surrounded contents too.
    1.35  ;;;  * [prefix] c	Change html tags on the point.
    1.36 +;;;			When typeing [prefix] c on `href="xxx"', you can 
    1.37 +;;;			change the reference link with completion.
    1.38  ;;;  * [prefix] t b	View current html with WWW browser
    1.39  ;;; 			(To activate this, never fail to set the lisp
    1.40  ;;; 			 variable yahtml-www-browser.  Recommended value
    1.41  ;;; 			 is "netscape")
    1.42 +;;;  * [prefix] a	YaTeX's accent mark's equivalent of yahtml.
    1.43 +;;;			This function can input $lt, $gt or so.
    1.44  ;;; 
    1.45 -;;; NOTE!  This program is  truly  tentative.  If  you find some  bright
    1.46 -;;; future with this, please send me a mail to drive me to maintain this :)
    1.47  
    1.48  
    1.49  (require 'yatex)
    1.50 @@ -128,6 +136,7 @@
    1.51        (yahtml-define-begend-key "bh" "HTML" map)
    1.52        (yahtml-define-begend-key "bH" "HEAD" map)
    1.53        (yahtml-define-begend-key "bt" "TITLE" map)
    1.54 +      (yahtml-define-begend-key "bT" "table" map)
    1.55        (yahtml-define-begend-key "bb" "BODY" map)
    1.56        (yahtml-define-begend-key "bd" "DL" map)
    1.57        (yahtml-define-begend-key "b1" "H1" map)
    1.58 @@ -146,13 +155,18 @@
    1.59      (YaTeX-define-key "k" 'yahtml-kill-* map)
    1.60      (YaTeX-define-key "c" 'yahtml-change-* map)
    1.61      (YaTeX-define-key "t" 'yahtml-browse-menu map)
    1.62 +    (YaTeX-define-key "a" 'yahtml-complete-mark map)
    1.63      ;;;;;(YaTeX-define-key "i" 'yahtml-fill-item map)
    1.64      )
    1.65  )
    1.66  
    1.67 +(defvar yahtml-paragraph-start
    1.68 +  (concat
    1.69 +   "^$\\|<[bh]r>\\|<p>\\|^[ \t]*</?\\(h[1-6]\\|p\\|d[ldt]\\|t[rdh]\\|li\\|body\\|html\\|head\\|title\\|ul\\|ol\\|dl\\|pre\\)>")
    1.70 +  "*Regexp of html paragraph separater")
    1.71  (defvar yahtml-paragraph-separate
    1.72    (concat
    1.73 -   "^$\\|<[bh]r>\\|<p>\\|^[ \t]*</?\\(h[1-6]\\|p\\|dl\\|dd\\|dt\\|li\\|body\\|html\\|head\\|title\\|ul\\|ol\\|dl\\|pre\\)>")
    1.74 +   "^$\\|<[bh]r>\\|<p>\\|^[ \t]*</?\\(h[1-6]\\|p\\|d[ldt]\\|li\\|body\\|html\\|head\\|title\\|ul\\|ol\\|dl\\|pre\\)>")
    1.75    "*Regexp of html paragraph separater")
    1.76  (defvar yahtml-syntax-table nil
    1.77    "*Syntax table for typesetting buffer")
    1.78 @@ -162,6 +176,7 @@
    1.79  	(make-syntax-table (standard-syntax-table)))
    1.80    (modify-syntax-entry ?\< "(" yahtml-syntax-table)
    1.81    (modify-syntax-entry ?\> ")" yahtml-syntax-table)
    1.82 +  (modify-syntax-entry ?\n " " yahtml-syntax-table)
    1.83  )
    1.84  (defvar yahtml-command-regexp "[A-Za-z0-9]+"
    1.85    "Regexp of constituent of html commands.")
    1.86 @@ -174,9 +189,12 @@
    1.87  
    1.88  (defvar yahtml-env-table
    1.89    '(("html") ("head") ("title") ("body") ("dl") ("a") ("form") ("select")
    1.90 +    ("textarea")
    1.91      ("OrderedList" . "ol")
    1.92      ("UnorderedList" . "ul")
    1.93      ("DefinitionList" . "dl")
    1.94 +    ("Preformatted" . "pre")
    1.95 +    ("table") ("tr") ("th") ("td")
    1.96      ("h1") ("h2") ("h3") ("h4") ("h5") ("h6") ("ul")))
    1.97  
    1.98  (defvar yahtml-itemizing-regexp
    1.99 @@ -224,7 +242,7 @@
   1.100  		yahtml-typeface-table))))
   1.101  
   1.102  (defvar yahtml-struct-name-regexp
   1.103 -  "\\<\\(h[1-6]\\|[uod]l\\|body\\|title\\|head\\|table\\|t[rhd]\\)")
   1.104 +  "\\<\\(h[1-6]\\|[uod]l\\|body\\|title\\|head\\|table\\|t[rhd]\\|pre\\|a\\|form\\|select\\)\\b")
   1.105  
   1.106  
   1.107  (defun yahtml-mode ()
   1.108 @@ -240,20 +258,23 @@
   1.109    (setq major-mode 'yahtml-mode
   1.110  	mode-name "yahtml")
   1.111    (make-local-variable 'YaTeX-ec) (setq YaTeX-ec "")
   1.112 -  (make-local-variable 'YaTeX-struct-begin) (setq YaTeX-struct-begin "<%1%2>")
   1.113 +  (make-local-variable 'YaTeX-struct-begin)
   1.114 +  (setq YaTeX-struct-begin "<%1%2>")
   1.115    (make-local-variable 'YaTeX-struct-end) (setq YaTeX-struct-end "</%1>")
   1.116    (make-local-variable 'YaTeX-struct-name-regexp)
   1.117    (setq YaTeX-struct-name-regexp yahtml-struct-name-regexp)
   1.118    (make-local-variable 'YaTeX-prefix-map)
   1.119    (make-local-variable 'YaTeX-command-token-regexp)
   1.120    (setq YaTeX-command-token-regexp yahtml-command-regexp)
   1.121 +  (make-local-variable 'YaTeX-comment-prefix)
   1.122 +  (setq YaTeX-comment-prefix "<!--")
   1.123    ;;(make-local-variable 'YaTeX-environment-indent)
   1.124    ;;(setq YaTeX-environment-indent 0)
   1.125    (make-local-variable 'fill-prefix)
   1.126    (setq fill-prefix nil)
   1.127    (make-local-variable 'paragraph-separate)
   1.128 -  (setq paragraph-separate yahtml-paragraph-separate
   1.129 -	paragraph-start  yahtml-paragraph-separate)
   1.130 +  (setq paragraph-start  yahtml-paragraph-start
   1.131 +	paragraph-separate yahtml-paragraph-separate)
   1.132    (make-local-variable 'comment-start)
   1.133    (make-local-variable 'comment-end)
   1.134    (setq comment-start "<!-- " comment-end " -->")
   1.135 @@ -452,6 +473,7 @@
   1.136  	 (save-excursion (insert (format "</%s>" form))))
   1.137       (if (search-backward "\"\"" p t) (forward-char 1))))
   1.138  
   1.139 +;;; ---------- Add-in ----------
   1.140  (defun yahtml-addin (form)
   1.141    "Check add-in function's existence and call it if exists."
   1.142     (let ((addin (concat "yahtml:" (downcase form))) s)
   1.143 @@ -461,6 +483,26 @@
   1.144  	 (concat " " s)
   1.145         "")))
   1.146  
   1.147 +
   1.148 +(defvar yahtml-completing-buffer nil)
   1.149 +(defun yahtml-collect-labels (&optional file)
   1.150 +  "Collect current buffers label (<a name=...>).
   1.151 +If optional argument FILE is specified collect labels in FILE."
   1.152 +  (let (list)
   1.153 +    (save-excursion
   1.154 +      (set-buffer yahtml-completing-buffer)
   1.155 +      (if file (set-buffer (find-file-noselect file)))
   1.156 +      (save-excursion
   1.157 +	(goto-char (point-min))
   1.158 +	(while (re-search-forward "<a\\b" nil t)
   1.159 +	  (skip-chars-forward " \t\n")
   1.160 +	  (if (looking-at "name\\s *=\\s *\"?#?\\([^\">]+\\)\"?>")
   1.161 +	      (setq list (cons
   1.162 +			  (list (concat "#" (YaTeX-match-string 1)))
   1.163 +			  list))))
   1.164 +	list)))
   1.165 +  )
   1.166 +
   1.167  (defvar yahtml-url-completion-map nil "Key map used in URL completion buffer")
   1.168  (if yahtml-url-completion-map nil
   1.169    (setq yahtml-url-completion-map
   1.170 @@ -472,7 +514,7 @@
   1.171  (defun yahtml-complete-url ()
   1.172    "Complete external URL from history or local file name."
   1.173    (interactive)
   1.174 -  (let (initial cmpl path dir file listfunc beg (p (point)))
   1.175 +  (let (initial i2 cmpl path dir file listfunc beg labels (p (point)))
   1.176      (setq initial (buffer-string))
   1.177      (cond
   1.178       ((string-match "^http:" initial)
   1.179 @@ -480,6 +522,19 @@
   1.180  	    listfunc (list 'lambda nil
   1.181  			   (list 'all-completions initial 'yahtml-urls))
   1.182  	    beg (point-min)))
   1.183 +     ((setq beg (string-match "#" initial))
   1.184 +      (or (equal beg 0)			;begin with #
   1.185 +	  (progn
   1.186 +	    (setq path (substring initial 0 beg))
   1.187 +	    (if (string-match "^/" path)
   1.188 +		(setq path (yahtml-url-to-path path)))))
   1.189 +      (setq initial (substring initial beg))
   1.190 +      (setq labels (yahtml-collect-labels path)
   1.191 +	    cmpl (try-completion initial labels)
   1.192 +	    listfunc (list 'lambda ()
   1.193 +			   (list 'all-completions
   1.194 +				 initial (list 'quote labels)))
   1.195 +	    beg (+ (point-min) beg)))
   1.196       (t
   1.197        (setq path (if (string-match "^/" initial)
   1.198  		     (yahtml-url-to-path initial)
   1.199 @@ -514,24 +569,28 @@
   1.200  (defun yahtml:a ()
   1.201    "Add-in function for <a>"
   1.202    (or yahtml-urls (yahtml-collect-url-history))
   1.203 +  (setq yahtml-completing-buffer (current-buffer))
   1.204  ;  (concat "href=\""
   1.205  ;	  (completing-read "href: " yahtml-urls)
   1.206  ;	  "\"")
   1.207    (message "(H)ref  (N)ame?")
   1.208    (cond
   1.209 -   ((string-match "[hH]" (char-to-string (read-char)))
   1.210 +   ((string-match "[nN]" (char-to-string (read-char)))
   1.211 +    (concat "name=\"" (read-string "name: ") "\""))
   1.212 +   (t
   1.213      (concat "href=\""
   1.214  	    (read-from-minibuffer "href: " "" yahtml-url-completion-map)
   1.215 -	    "\""))
   1.216 -   (t (concat "name=\"" (read-string "name: ") "\""))))
   1.217 +	    "\""))))
   1.218  
   1.219  (defun yahtml:img ()
   1.220    "Add-in function for <img>"
   1.221    (or yahtml-urls (yahtml-collect-url-history))
   1.222    (let ((src (read-file-name "src: " "" nil nil ""))
   1.223 -	(alg (completing-read "align: " '(("top") ("middle") ("bottom")))))
   1.224 +	(alg (completing-read "align: " '(("top") ("middle") ("bottom"))))
   1.225 +	(alt (read-string "alt: ")))
   1.226      (concat "src=\"" src "\""
   1.227 -	    (if (string< "" alg) (concat " align=\"" alg "\"")))))
   1.228 +	    (if (string< "" alg) (concat " align=\"" alg "\""))
   1.229 +	    (if (string< "" alt) (concat " alt=\"" alt "\"")))))
   1.230  
   1.231  (defun yahtml:form ()
   1.232    "Add-in function `form' input format"
   1.233 @@ -576,7 +635,24 @@
   1.234       (if (string< "" size) (concat " size=\"" size "\""))
   1.235       (if (string< "" maxlength) (concat " maxlength=\"" maxlength "\""))
   1.236      )))
   1.237 -	
   1.238 +
   1.239 +(defun yahtml:textarea ()
   1.240 +  "Add-in function for `textarea'"
   1.241 +  (interactive)
   1.242 +  (let (name rows cols)
   1.243 +    (setq name (read-string "Name: ")
   1.244 +	  cols (read-string "Columns: "
   1.245 +	  rows (read-string "Rows: ")))
   1.246 +    (concat
   1.247 +     (concat (if yahtml-prefer-upcases "NAME=" "name=")
   1.248 +	     "\"" name "\"")
   1.249 +     (if (string< "" cols)
   1.250 +	 (concat " " (if yahtml-prefer-upcases "COLS" "cols") "=" cols))
   1.251 +     (if (string< "" rows)
   1.252 +	 (concat " " (if yahtml-prefer-upcases "ROWS" "rows") "=" rows)))))
   1.253 +
   1.254 +
   1.255 +;;; ---------- Simple tag ----------
   1.256  (defun yahtml-insert-tag (region-mode &optional tag)
   1.257    "Insert <TAG> </TAG> and put cursor inside of them."
   1.258    (interactive "P")
   1.259 @@ -769,7 +845,7 @@
   1.260  	     (string-match "img" tag)
   1.261  	     (save-excursion
   1.262  	       (re-search-backward "<\\s *img" nil t)
   1.263 -	       (re-search-forward "src=\"?\\([^\"> ]+\\)\"?>")
   1.264 +	       (re-search-forward "src=\"?\\([^\"> ]+\\)\"?")
   1.265  	       (match-beginning 1)
   1.266  	       (setq image
   1.267  		     (buffer-substring (match-beginning 1) (match-end 1)))))
   1.268 @@ -833,8 +909,28 @@
   1.269  	(default (append yahtml-env-table yahtml-typeface-table))
   1.270  	(user (append yahtml-user-env-table yahtml-user-typeface-table))
   1.271  	(tmp (append yahtml-tmp-env-table yahtml-tmp-typeface-table))
   1.272 -	)
   1.273 -    (if tag
   1.274 +	href b1 e1)
   1.275 +    (cond
   1.276 +     (tag
   1.277 +      (cond
   1.278 +       ((and (equal tag "a")
   1.279 +	     (save-excursion
   1.280 +	       (and
   1.281 +		(re-search-backward "<a" nil t)
   1.282 +		(goto-char (match-end 0))
   1.283 +		(skip-chars-forward " \t\n")
   1.284 +		(>= p (point))
   1.285 +		(looking-at "href\\s *=\\s *\"?\\([^\"> \t\n]+\\)\"?")
   1.286 +		(< p (match-end 0)))))
   1.287 +	(setq b1 (match-beginning 1) e1 (match-end 1)
   1.288 +	      href (read-from-minibuffer
   1.289 +		    "Change href to: " "" yahtml-url-completion-map))
   1.290 +	(if (string< "" href)
   1.291 +	    (progn
   1.292 +	      (delete-region b1 e1)
   1.293 +	      (goto-char b1)
   1.294 +	      (insert href))))
   1.295 +       (t
   1.296  	(save-excursion
   1.297  	  (if (= (aref tag 0) ?/) (setq tag (substring tag 1)))
   1.298  	  (or (= (char-after (point)) ?<) (skip-chars-backward "^<"))
   1.299 @@ -861,7 +957,7 @@
   1.300  	  (insert (format "%s%s" tag (yahtml-addin tag)))
   1.301  	  (goto-char q)
   1.302  	  (delete-region (point) (progn (skip-chars-forward "^>") (point)))
   1.303 -	  (insert tag)))))
   1.304 +	  (insert tag))))))))
   1.305  
   1.306  (defun yahtml-change-* ()
   1.307    "Change current position's HTML tag (set)."
   1.308 @@ -903,8 +999,8 @@
   1.309  (defvar yahtml-hate-too-deep-indentation nil)
   1.310  (defun yahtml-indent-line ()
   1.311    (interactive)
   1.312 -  (let ((envs "[uod]l\\|table\\|t[rhd]")
   1.313 -	(itms "<\\(dt\\|dd\\|li\\|t[rdh]\\)>")
   1.314 +  (let ((envs "[uod]l\\|table\\|t[rhd]\\|select\\|a\\b")
   1.315 +	(itms "<\\(dt\\|dd\\|li\\|t[rdh]\\|option\\)>")
   1.316  	inenv p col peol (case-fold-search t))
   1.317      (save-excursion
   1.318        (beginning-of-line)
   1.319 @@ -1018,17 +1114,20 @@
   1.320      (cond
   1.321       ((string-match "^/" file)
   1.322        (while list
   1.323 -	(if (string-match (concat "^" (regexp-quote (car (car list)))) basedir)
   1.324 +	(if (file-directory-p (car (car list)))
   1.325  	    (progn
   1.326  	      (setq url (cdr (car list)))
   1.327  	      (if (string-match "\\(http://[^/]*\\)/" url)
   1.328  		  (setq docroot (substring url (match-end 1)))
   1.329  		(setq docroot url))
   1.330 -	      (if (string-match (regexp-quote docroot) file)
   1.331 +	      (if (string-match (concat "^" (regexp-quote docroot)) file)
   1.332  		  (setq realpath
   1.333  			(expand-file-name
   1.334  			 (substring
   1.335 -			  file (min (1+ (match-end 0)) (length file)))
   1.336 +			  file
   1.337 +			  (if (= (aref file (1- (match-end 0))) ?/)
   1.338 +			      (match-end 0) ; "/foo"
   1.339 +			    (min (1+ (match-end 0)) (length file)))) ; "/~foo"
   1.340  			 (car (car list)))))
   1.341  	      (if realpath
   1.342  		  (progn (setq list nil)
   1.343 @@ -1099,6 +1198,11 @@
   1.344        (insert (if yahtml-prefer-upcases "<DT> " "<dt> ")))
   1.345      (yahtml-indent-line)))
   1.346  
   1.347 +(defun yahtml-intelligent-newline-select ()
   1.348 +  (interactive)
   1.349 +  (insert "<" (if yahtml-prefer-upcases "OPTION" "option") "> ")
   1.350 +  (yahtml-indent-line))
   1.351 +
   1.352  ;;; ---------- Marking ----------
   1.353  (defun yahtml-mark-begend ()
   1.354    "Mark current tag"
   1.355 @@ -1113,7 +1217,20 @@
   1.356    (forward-list 1)
   1.357    (if (eolp) (forward-char 1)))
   1.358  
   1.359 -;;; ---------- ----------
   1.360 +;;; ---------- complete marks ----------
   1.361 +(defun yahtml-complete-mark ()
   1.362 +  "Complete &gt, &lt, &asterisk, and &quote."
   1.363 +  (interactive)
   1.364 +  (message "1:< 2:> 3:& 4:\"")
   1.365 +  (let ((c (read-char)))
   1.366 +    (setq c (if (or (< c ?0) (> c ?5))
   1.367 +		(string-match (regexp-quote (char-to-string c)) "<>&\"")
   1.368 +	      (- c ?1)))
   1.369 +    (if (or (< c 0) (> c 4))
   1.370 +	nil
   1.371 +      (insert (format "&%s;" (nth c '("lt" "gt" "amp" "quot")))))))
   1.372 +
   1.373 +
   1.374  ;;; ---------- ----------
   1.375  ;;; ---------- ----------
   1.376