diff --git a/newpage.rb b/newpage.rb new file mode 100755 index 0000000..6d9db1e --- /dev/null +++ b/newpage.rb @@ -0,0 +1,128 @@ +#!/usr/bin/env ruby +# THIS is very very tentative. Insufficient examination of function. +# Create new HTML file referring other HTML file in the same directory. +# (C)2010 by HIROSE Yuuji [yuuji@yatex.org] +# Last modified Mon Sep 6 16:16:33 2010 on firestorm +# $Id$ +# http://www.yatex.org +# Example: +# newpage.rb Create new index.html by copying template. +# newpage.rb foo.html Create new foo.html whose by copying header +# and footer from index.html. +# newpage.rb d/sub.html Create new directory d (if necessary) and +# d/sub.html by copying header/footer from +# index.html in a same directory or parent +# directory rewriting href to css file +# considering relative path. +# newpage.rb -o [file] Forcibly overwrite existing file. +# newpage.rb -c cssfile Set `cssfile' as defualt css. +# newpage.rb -t template Set `template' as HTML template. +require 'fileutils' + +mydir=File.dirname($0) +myname=File.basename($0, ".rb") + + +index = 'index.html' +cssdefault = nil +overwrite = nil +template = __FILE__ #File.expand_path(myname+".html", mydir) + +def guesscss(dir) + +end + +while ARGV[0] && /^-/ =~ (a0=ARGV[0].dup) && ARGV.shift + break if /^--$/ =~ a0 + while /^-[A-Za-z]/ =~ a0 + case a0 + when "-c" # css + ARGV.shift; cssdefault = ARGV[0] + when "-t" # template + ARGV.shift; cssdefault = ARGV[0] + when "-o" # overwrite + overwrite = true + end + a0.sub!(/-.(.*)/, '-\\1') + end +end + +outfile = ARGV[0]||index +if !overwrite && test(?s, outfile) then + STDERR.printf("File \`%s' exists. Use -o option to overwrite.\n", outfile) + exit 1 +end + +# set css default file +dots = 0 +of = outfile +dots+=1 while "." != (of=File.dirname(of)) +cssdir = "../"*dots + +# set copy source +outdir = File.dirname(outfile) +if "index.html" == File.basename(outfile) + src = (dots == 0 ? template : "index.html") +elsif test(?s, outdir+"/index.html") + src = outdir+"/index.html" +else + src = template +end + +FileUtils.mkdir_p(outdir) + +cssfile = cssdir+"main.css" +name = File.basename(outfile, ".html") +begin + open(outfile, "w") do |out| + #IO.foreach(src) do |line| + if src == __FILE__ + input = DATA + else + input = open(src, "r") + end + begin + html = input.readlines.join + html.sub!(%r|^|i, sprintf("

%s

\n", name)) + if !html.gsub!("__CSSFILE__", cssfile) + html.gsub!(/href=(['\"])(.*\.css)\1/, 'href="'+cssdir+'\2"') + end + html.gsub!("__TITLE__", name) + out.print html + ensure + input.close + end + end + printf(<<_EOS_, outfile, name) +%s +_EOS_ +rescue + p $! + STDERR.printf(<<'_EOS_', outfile, outfile) +Cannot output to [%s]. Do + chmod +w %s +or + chmod +w . +or change output directory. +_EOS_ + exit 1 +end + +__END__ + + +__TITLE__ + + + + + +

__TITLE__

+ + + + diff --git a/yahtml.el b/yahtml.el index a488e97..e4ffb1f 100644 --- a/yahtml.el +++ b/yahtml.el @@ -1,6 +1,6 @@ ;;; -*- Emacs-Lisp -*- ;;; (c) 1994-2010 by HIROSE Yuuji [yuuji(@)yatex.org] -;;; Last modified Fri Feb 12 21:30:03 2010 on firestorm +;;; Last modified Mon Sep 13 08:09:46 2010 on firestorm ;;; $Id$ (defconst yahtml-revision-number "1.74.2" @@ -417,7 +417,7 @@ ("DefinitionList" . "dl") ("Preformatted" . "pre") ("table") ("thead") ("tbody") ("tfoot") ("tr") ("th") ("td") - ("address") + ("address") ("button") ("h1") ("h2") ("h3") ("h4") ("h5") ("h6") ;; ("p") ;This makes indentation screwed up! ("style") ("script") ("noscript") ("div") ("object") ("ins") ("del") @@ -880,6 +880,25 @@ "class(or class list delimited by \\[quoted-insert] SPC): ")) nil YaTeX-minibuffer-completion-map nil))) +(defvar yahtml-newpage-command "newpage.rb" + "*Command name to create new HTML file referring to index.html. +This command should create new HTML file named argument 1 and +output string like `anchor tag'. +This program should take -o option to overwrite existing HTML file.") +(defun yahtml-newpage (file ov) + "Create newpage via newpage script" + (interactive + (list + (let (insert-default-directory) + (read-file-name "New webpage file name: " "")) + current-prefix-arg)) + (if (and (file-exists-p file) (not ov)) + (error "%s already exists. Call this with universal argument to force overwrite." file)) + (insert (substring + (YaTeX-command-to-string + (concat yahtml-newpage-command " " (if ov "-o ") file)) + 0 -1))) + ;;; ---------- Add-in ---------- (defun yahtml-addin (form) "Check add-in function's existence and call it if exists." @@ -888,6 +907,7 @@ (and (setq a (yahtml-css-get-element-completion-alist form)) (not (equal last-command-char ?\C-j)) (memq yahtml-current-completion-type '(multiline inline)) + (not (string-match "#" form)) (yahtml-make-optional-argument ;should be made generic? "class" (yahtml-read-css a))) (if (and (intern-soft addin) (fboundp (intern-soft addin)) @@ -1116,6 +1136,10 @@ ((eq alist 'file) (let ((insert-default-directory)) (read-file-name prompt "" default nil ""))) + ((eq alist 'command) + (if (fboundp 'read-shell-command) + (read-shell-command prompt) + (read-string prompt))) ((and alist (symbolp alist)) (completing-read prompt (symbol-value alist) nil nil default)) (alist @@ -1563,6 +1587,16 @@ "Add-in function for abbr." (yahtml-make-optional-argument "title" (yahtml-read-parameter "title"))) +(defun yahtml:button () + (concat + (yahtml-make-optional-argument + "name" (yahtml-read-parameter "name")) + (yahtml-make-optional-argument + "type" (yahtml-read-parameter + "type" "button" '(("submit")("reset")("button")))) + (yahtml-make-optional-argument + "value" (yahtml-read-parameter "value")))) + ;;; ---------- Simple tag ---------- (defun yahtml-insert-tag (region-mode &optional tag) "Insert and put cursor inside of them." @@ -1656,7 +1690,8 @@ (format "%s=\"%s\"--" (if (string-match "/" file) "virtual" "file") file))) (defun yahtml:!--\#exec () - (format "cmd=\"%s\"--" (yahtml-read-parameter "cmd" "" '(("cmd" . file))))) + (format "cmd=\"%s\"--" + (yahtml-read-parameter "cmd" "" '(("cmd" . command))))) ;;; ---------- Jump ---------- (defun yahtml-on-href-p () @@ -2247,6 +2282,39 @@ (goto-char (get 'YaTeX-inner-environment 'point)))) e)) +(defun yahtml-untranslate-string (str) + "Untranslate entity reference." + (let ((md (match-data)) (left "") (right str) b0 ch + (ct (append yahtml-entity-reference-chars-alist + yahtml-entity-reference-chars-alist-default)) + (revrex yahtml-entity-reference-chars-reverse-regexp)) + (unwind-protect + (progn + (while (string< "" right) + (cond + ((string-match revrex right) + (setq ch (YaTeX-rassoc + (substring right (match-beginning 1) (match-end 1))) + b0 (substring right 0 (match-beginning 0)) + right (substring right (match-end 0)) + left (concat left + (substring right 0 (match-beginning 0)) + (char-to-string ch)))) + ((string-match "\\&#\\(x\\)?\\([0-9a-f]+\\);" right) + (setq ch (substring right (match-beginning 2) (match-end 2)) + b0 (substring right 0 (match-beginning 0)) + right (substring right (match-end 0)) + left (concat left + b0 + (char-to-string + (if (match-beginning 1) + (YaTeX-hex ch) + (string-to-number ch)))))) + (t (setq left (concat left right) + right "")))) + left) + (store-match-data md)))) + ;;; ---------- filling ---------- (defvar yahtml-saved-move-to-column (symbol-function 'move-to-column)) (defun yahtml-move-to-column (col &optional force) @@ -2453,9 +2521,9 @@ ;;; ---------- Lint and Browsing ---------- ;;; (defun yahtml-browse-menu () - "Browsing menu" + "Browsing or other external process invokation menu." (interactive) - (message "J)weblint p)Browse R)eload...") + (message "J)weblint p)Browse R)eload N)ewpage...") (let ((c (char-to-string (read-char)))) (cond ((string-match "j" c) @@ -2463,7 +2531,9 @@ ((string-match "[bp]" c) (yahtml-browse-current-file)) ((string-match "r" c) - (yahtml-browse-reload))))) + (yahtml-browse-reload)) + ((string-match "n" c) + (call-interactively 'yahtml-newpage))))) (if (fboundp 'wrap-function-to-control-ime) (wrap-function-to-control-ime 'yahtml-browse-menu t nil)) @@ -2476,10 +2546,12 @@ (interactive "bCall lint on buffer: ") (setq buf (get-buffer buf)) (YaTeX-save-buffers) - (YaTeX-typeset - (concat yahtml-lint-program " " - (file-name-nondirectory (buffer-file-name buf))) - yahtml-lint-buffer "lint" "lint")) + (let ((bcmd (YaTeX-get-builtin "lint"))) + (and bcmd (setq bcmd (yahtml-untranslate-string bcmd))) + (YaTeX-typeset + (concat (or bcmd yahtml-lint-program) + " " (file-name-nondirectory (buffer-file-name buf))) + yahtml-lint-buffer "lint" "lint"))) (defun yahtml-file-to-url (file) "Convert local unix file name to URL. @@ -2685,7 +2757,7 @@ (cond ((and (> cols 0) (memq (read-char) '(?d ?D))) ;Duplication mode - (setq line (YaTeX-buffer-substring (point) cp))) + (setq line (YaTeX-buffer-substring (point) (1- cp)))) (t ;empty cells (setq line "" i 0) (if (> cols 0) diff --git a/yatex.new b/yatex.new index f6a8948..909f4cd 100644 --- a/yatex.new +++ b/yatex.new @@ -5,6 +5,9 @@ [prefix] t e �Ń|�C���g�ʒu���܂ފ‹��������‹����^�C�v�Z�b�g�B M-C-SPC �Ŋ‹������łȂ������‹����}�[�N����B [prefix] t d �Ń^�C�v�Z�b�^�N�������̂��� dvipdfmx ���N���B + === yahtml === + [prefix] t �u���E�U���j���[�Ɂun:�V�K�y�[�W�쐬�v��lj�(����)�B + [prefix] t j ��lint�R�}���h�� �Ŏw��B 1.74 === yatex === YaTeX-kanji-code �� 4 �̂Ƃ��� UTF-8 �Ƃ����B diff --git a/yatexadd.el b/yatexadd.el index c0df80c..70d92df 100644 --- a/yatexadd.el +++ b/yatexadd.el @@ -2,8 +2,8 @@ ;;; YaTeX add-in functions. ;;; yatexadd.el rev.18 ;;; (c)1991-2006 by HIROSE Yuuji.[yuuji@yatex.org] -;;; Last modified Thu Oct 15 09:18:40 2009 on firestorm -;;; $Id: yatexadd.el,v f14ec50103d0 2009/09/27 22:55:44 yuuji $ +;;; Last modified Thu Sep 9 09:08:19 2010 on firestorm +;;; $Id$ ;;; ;;Sample functions for LaTeX environment. @@ -1665,7 +1665,7 @@ ("Emerald") ("JungleGreen") ("SeaGreen") ("Green") ("ForestGreen") ("PineGreen") ("LimeGreen") ("YellowGreen") ("SpringGreen") ("OliveGreen") ("RawSienna") ("Sepia") ("Brown") ("Tan") ("Gray") ("Black") ("White")) - "Colors defined in $TEXMF/tex/plain/colordvi.tex") + "Colors defined in $TEXMF/tex/plain/dvips/colordvi.tex") (defvar YaTeX:latex2e-basic-color-alist '(("black") ("white") ("red") ("blue") ("yellow") ("green") ("cyan") diff --git a/yatexlib.el b/yatexlib.el index 8ef5b25..58bb761 100644 --- a/yatexlib.el +++ b/yatexlib.el @@ -2,7 +2,7 @@ ;;; YaTeX and yahtml common libraries, general functions and definitions ;;; yatexlib.el ;;; (c)1994-2009 by HIROSE Yuuji.[yuuji@yatex.org] -;;; Last modified Thu May 27 15:09:44 2010 on firestorm +;;; Last modified Sat Sep 11 11:40:11 2010 on firestorm ;;; $Id$ ;; General variables @@ -822,6 +822,21 @@ (win-switch-to-window 1 (- last-command-char win:base-key))) ;;;###autoload +(defun YaTeX-command-to-string (cmd) + (if (fboundp 'shell-command-to-string) + (funcall 'shell-command-to-string cmd) + (let ((tbuf " *tmpout*")) + (if (get-buffer-create tbuf) (kill-buffer tbuf)) + (let ((standard-output (get-buffer-create tbuf))) + (unwind-protect + (save-excursion + (call-process + shell-file-name nil tbuf nil YaTeX-shell-command-option cmd) + (set-buffer tbuf) + (buffer-string)) + (kill-buffer tbuf)))))) + +;;;###autoload (defun YaTeX-reindent (col) "Remove current indentation and reindento to COL column." (save-excursion @@ -1052,6 +1067,37 @@ (get-file-buffer pf) (switch-to-buffer (get-file-buffer pf))))) +(defun YaTeX-get-builtin (key) + "Read source built-in command of %# usage." + (catch 'builtin + (let ((bl (delq nil (list (current-buffer) + (and YaTeX-parent-file + (get-file-buffer YaTeX-parent-file))))) + (leader (or (cdr-safe (assq major-mode + '((yatex-mode . "%#") + (yahtml-mode . "