changeset 142:b65b3dc543d1 dev

The function YaTeX-hex added.
author yuuji@gentei.org
date Sat, 11 Sep 2010 11:40:56 +0900
parents 13a717bee066
children c9da37260ca9
files yatexlib.el
diffstat 1 files changed, 50 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/yatexlib.el	Thu Sep 09 09:11:25 2010 +0900
+++ b/yatexlib.el	Sat Sep 11 11:40:56 2010 +0900
@@ -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 Wed Jul  7 06:48:48 2010 on firestorm
+;;; Last modified Sat Sep 11 11:40:11 2010 on firestorm
 ;;; $Id$
 
 ;; General variables
@@ -1067,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 . "<!-- #"))))
+		      "")))
+      (save-excursion
+	(while bl
+	  (set-buffer (car bl))
+	  (save-excursion
+	    (goto-char (point-min))
+	    (if (and (re-search-forward
+		      (concat "^" (regexp-quote (concat leader key))) nil t)
+		     (not (eolp)))
+		(throw 'builtin
+		       (YaTeX-buffer-substring
+			(progn
+			  (skip-chars-forward " \t" (point-end-of-line))
+			  (point))
+			(if (string< "" comment-end)
+			    (progn
+			      (search-forward
+			       comment-end (point-end-of-line) t)
+			      (match-beginning 0))
+			  (point-end-of-line))))))
+	  (setq bl (cdr bl)))))))
+
 ;;;VER2
 (defun YaTeX-insert-struc (what env)
   (cond
@@ -1088,6 +1119,24 @@
    ((fboundp 'truncate-string) (truncate-string str width))
    (t (substring str 0 width))))
 
+(defun YaTeX-hex (str)
+  "Return int expressed by hexadecimal string STR."
+  (if (string< "20" emacs-version)
+      (string-to-number str 16)
+    (let ((md (match-data)))
+      (unwind-protect
+	  (if (string-match "[^0-9a-f]" str)
+	      (error "Non hexadecimal character in %s" str)
+	    (let ((i 0) d)
+	      (setq str (downcase str))
+	      (while (string< "" str)
+		(setq d (+ 0 (string-to-char str)) ; + 0 for XEmacs
+		      i (+ (* 16 i) (- d (if (<= d ?9) ?0 (- ?a 10))))
+		      str (substring str 1)))
+	      i))
+	(store-match-data md)))))
+
+
 ;;; Function for menu support
 (defun YaTeX-define-menu (keymap bindlist)
   "Define KEYMAP(symbol)'s menu-bindings according to BINDLIST.

yatex.org