yatex

changeset 438:1b9beabd3fd1 dev

Add add-ins for <audio> and <video>
author HIROSE Yuuji <yuuji@gentei.org>
date Sat, 13 Aug 2016 16:53:59 +0900
parents 27f00e6e0150
children 2521a95043af
files yahtml.el
diffstat 1 files changed, 68 insertions(+), 7 deletions(-) [+]
line diff
     1.1 --- a/yahtml.el	Sat Jul 16 13:33:36 2016 +0859
     1.2 +++ b/yahtml.el	Sat Aug 13 16:53:59 2016 +0900
     1.3 @@ -1,6 +1,6 @@
     1.4  ;;; yahtml.el --- Yet Another HTML mode -*- coding: sjis -*-
     1.5  ;;; (c) 1994-2015 by HIROSE Yuuji [yuuji(@)yatex.org]
     1.6 -;;; Last modified Sat Jul 16 13:32:35 2016 on firestorm
     1.7 +;;; Last modified Sat Aug 13 16:52:40 2016 on mt09
     1.8  ;;; $Id$
     1.9  
    1.10  (defconst yahtml-revision-number "1.78.1"
    1.11 @@ -425,7 +425,7 @@
    1.12  
    1.13  ;;; Completion tables for `form'
    1.14  (defvar yahtml-form-table
    1.15 -  '(("img") ("input") ("link") ("meta") ("label")))
    1.16 +  '(("img") ("input") ("link") ("meta") ("label") ("source")))
    1.17  (defvar yahtml-user-form-table nil)
    1.18  (defvar yahtml-tmp-form-table nil)
    1.19  (defvar yahtml-last-form "img")
    1.20 @@ -443,6 +443,8 @@
    1.21      ;; ("p") ;This makes indentation screwed up!
    1.22      ("style") ("script") ("noscript") ("div") ("object") ("ins") ("del")
    1.23      ("option") ("datalist")
    1.24 +    ;;HTML5
    1.25 +    ("video") ("audio")
    1.26      ))
    1.27  
    1.28  (if yahtml-html4-strict
    1.29 @@ -870,7 +872,7 @@
    1.30  	(insert "\n")
    1.31  	(indent-to-column cc)
    1.32  	(insert (format "</%s>" cmd)))
    1.33 -      (if (string-match "^a\\|p$" cmd)	;aとp決め打ちってのが美しくない…
    1.34 +      (if (string-match "^[ap]$" cmd)	;aとp決め打ちってのが美しくない…
    1.35  	  (newline)
    1.36  	(yahtml-intelligent-newline nil))
    1.37        (yahtml-indent-line))))
    1.38 @@ -941,7 +943,7 @@
    1.39        (and (setq a (yahtml-css-get-element-completion-alist form))
    1.40  	   (not (equal (YaTeX-last-key) ?\C-j))
    1.41  	   (memq yahtml-current-completion-type '(multiline inline))
    1.42 -	   (not (string-match "#" form))
    1.43 +	   (not (string-match "#\\|source" form))
    1.44  	   (yahtml-make-optional-argument ;should be made generic?
    1.45  	    "class" (yahtml-read-css a form)))
    1.46        (if (and (intern-soft addin) (fboundp (intern-soft addin))
    1.47 @@ -1157,7 +1159,7 @@
    1.48    '(("align" ("top") ("middle") ("bottom") ("left") ("right") ("center"))
    1.49      ("clear" ("left") ("right") ("center") ("all") ("none"))
    1.50      ("lang" ("ja") ("en") ("kr") ("ch") ("fr"))
    1.51 -    ("src" . file) ("file" . file)
    1.52 +    ("src" . file) ("file" . file) ("poster" . file)
    1.53      ("background" . file)
    1.54      ("class file name" . file) ("data" . file)
    1.55      ("method" ("POST") ("GET"))
    1.56 @@ -1181,7 +1183,7 @@
    1.57      ("image/jpeg") ("image/gif") ("image/tiff") ("image/png") ("video/mpeg"))
    1.58    "Alist of content-types")
    1.59  
    1.60 -(defun yahtml-read-parameter (par &optional default alist)
    1.61 +(defun yahtml-read-parameter (par &optional default alist predicate)
    1.62    (let* ((alist
    1.63  	  (cdr-safe (assoc (downcase par)
    1.64  			   (or alist yahtml-parameters-completion-alist))))
    1.65 @@ -1190,7 +1192,7 @@
    1.66      (cond
    1.67       ((eq alist 'file)
    1.68        (let ((insert-default-directory))
    1.69 -	(read-file-name prompt "" default nil "")))
    1.70 +	(read-file-name prompt "" default nil "" predicate)))
    1.71       ((eq alist 'command)
    1.72        (if (fboundp 'read-shell-command)
    1.73  	  (read-shell-command prompt)
    1.74 @@ -1202,6 +1204,17 @@
    1.75        (completing-read-with-history prompt alist nil nil default))
    1.76       (t 
    1.77        (read-string-with-history prompt default)))))
    1.78 +
    1.79 +(defun yahtml-read-file-name-regexp
    1.80 +    (prompt regexp &optional dir default-filename mustmatch initial)
    1.81 +  (let ((pred
    1.82 +	 (function
    1.83 +	  (lambda (f)
    1.84 +	    (or (file-name-directory f)
    1.85 +		(string-match regexp f)))))
    1.86 +	(insert-default-directory nil))
    1.87 +    (read-file-name prompt dir default-filename mustmatch initial pred)))
    1.88 +    
    1.89        
    1.90  (defun yahtml-make-optional-argument (opt arg)
    1.91    "Make optional argument string."
    1.92 @@ -1779,6 +1792,38 @@
    1.93    (format "cmd=\"%s\"--"
    1.94  	  (yahtml-read-parameter "cmd" "" '(("cmd" . command)))))
    1.95  
    1.96 +(defun yahtml:media-read-options (&optional opts-alist)
    1.97 +  (let*((delim " ")
    1.98 +	(minibuffer-completion-table
    1.99 +	 (or opts-alist '(("autoplay") ("controls") ("loop") ("preload"))))
   1.100 +	(quotekey (substitute-command-keys "\\[quoted-insert]")))
   1.101 +    (read-from-minibuffer-with-history
   1.102 +     (format "Media Opts(`%s SPC' for more options): " quotekey)
   1.103 +     "controls" YaTeX-minibuffer-completion-map)))
   1.104 +
   1.105 +(defun yahtml:audio ()
   1.106 +  ;preload autoplay loop controls: `src' be specified via `source'
   1.107 +  (yahtml:media-read-options))
   1.108 +
   1.109 +(defun yahtml:video ()
   1.110 +  ;`src' be specified via `source'
   1.111 +  (let ((poster (yahtml-make-optional-argument
   1.112 +		 "poster"
   1.113 +		 (yahtml-read-file-name-regexp
   1.114 +		  "Poster: " "\\.\\(gif\\|png\\|jpg\\|w?bmp\\|pict\\|tif\\)"
   1.115 +		  "")))
   1.116 +	(opts (yahtml:media-read-options)))
   1.117 +    (concat poster (if (string< "" opts) (concat " " opts)))))
   1.118 +
   1.119 +(defvar yahtml-media-file-regexp
   1.120 +  "\\.\\(mp[0-9]\\|wav\\|og[gv]\\|opus\\|aac\\)"
   1.121 +  "*Default filename regexp of media files.")
   1.122 +
   1.123 +(defun yahtml:source ()
   1.124 +  ;; source element must have src attribute
   1.125 +  (format "src=\"%s\"" (yahtml-read-file-name-regexp
   1.126 +			"source: " yahtml-media-file-regexp "" "" nil "")))
   1.127 +    
   1.128  ;;; ---------- Jump ----------
   1.129  (defun yahtml-on-href-p ()
   1.130    "Check if point is on href clause."
   1.131 @@ -2986,6 +3031,22 @@
   1.132  	    (goto-char (+ 8 cp))
   1.133  	    (yahtml-indent-line)))))))
   1.134  
   1.135 +(defun yahtml-intelligent-newline-audio ()
   1.136 +  (let (b e)
   1.137 +    (if (save-excursion
   1.138 +	  (goto-char (setq b (get 'YaTeX-inner-environment 'point)))
   1.139 +	  (forward-list 1)
   1.140 +	  (setq e (point))
   1.141 +	  (catch 'src
   1.142 +	    (while (re-search-forward "\\s src\\>" e t)
   1.143 +	      (skip-chars-forward " \t\n")
   1.144 +	      (and (looking-at "=") (throw 'src t)))))
   1.145 +	;; if src= attribute found, do nothing
   1.146 +	(setq yahtml-last-begend "p")
   1.147 +      (yahtml-insert-single "source")
   1.148 +      )))
   1.149 +(fset 'yahtml-intelligent-newline-video 'yahtml-intelligent-newline-audio)
   1.150 +
   1.151  ;;; ---------- Marking ----------
   1.152  (defun yahtml-mark-begend ()
   1.153    "Mark current tag"