yatex

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 diff
     1.1 --- a/yatexlib.el	Thu Sep 09 09:11:25 2010 +0900
     1.2 +++ b/yatexlib.el	Sat Sep 11 11:40:56 2010 +0900
     1.3 @@ -2,7 +2,7 @@
     1.4  ;;; YaTeX and yahtml common libraries, general functions and definitions
     1.5  ;;; yatexlib.el
     1.6  ;;; (c)1994-2009 by HIROSE Yuuji.[yuuji@yatex.org]
     1.7 -;;; Last modified Wed Jul  7 06:48:48 2010 on firestorm
     1.8 +;;; Last modified Sat Sep 11 11:40:11 2010 on firestorm
     1.9  ;;; $Id$
    1.10  
    1.11  ;; General variables
    1.12 @@ -1067,6 +1067,37 @@
    1.13  	 (get-file-buffer pf)
    1.14  	 (switch-to-buffer (get-file-buffer pf)))))
    1.15  
    1.16 +(defun YaTeX-get-builtin (key)
    1.17 +  "Read source built-in command of %# usage."
    1.18 +  (catch 'builtin
    1.19 +    (let ((bl (delq nil (list (current-buffer)
    1.20 +			      (and YaTeX-parent-file
    1.21 +				   (get-file-buffer YaTeX-parent-file)))))
    1.22 +	  (leader (or (cdr-safe (assq major-mode
    1.23 +				      '((yatex-mode . "%#")
    1.24 +					(yahtml-mode . "<!-- #"))))
    1.25 +		      "")))
    1.26 +      (save-excursion
    1.27 +	(while bl
    1.28 +	  (set-buffer (car bl))
    1.29 +	  (save-excursion
    1.30 +	    (goto-char (point-min))
    1.31 +	    (if (and (re-search-forward
    1.32 +		      (concat "^" (regexp-quote (concat leader key))) nil t)
    1.33 +		     (not (eolp)))
    1.34 +		(throw 'builtin
    1.35 +		       (YaTeX-buffer-substring
    1.36 +			(progn
    1.37 +			  (skip-chars-forward " \t" (point-end-of-line))
    1.38 +			  (point))
    1.39 +			(if (string< "" comment-end)
    1.40 +			    (progn
    1.41 +			      (search-forward
    1.42 +			       comment-end (point-end-of-line) t)
    1.43 +			      (match-beginning 0))
    1.44 +			  (point-end-of-line))))))
    1.45 +	  (setq bl (cdr bl)))))))
    1.46 +
    1.47  ;;;VER2
    1.48  (defun YaTeX-insert-struc (what env)
    1.49    (cond
    1.50 @@ -1088,6 +1119,24 @@
    1.51     ((fboundp 'truncate-string) (truncate-string str width))
    1.52     (t (substring str 0 width))))
    1.53  
    1.54 +(defun YaTeX-hex (str)
    1.55 +  "Return int expressed by hexadecimal string STR."
    1.56 +  (if (string< "20" emacs-version)
    1.57 +      (string-to-number str 16)
    1.58 +    (let ((md (match-data)))
    1.59 +      (unwind-protect
    1.60 +	  (if (string-match "[^0-9a-f]" str)
    1.61 +	      (error "Non hexadecimal character in %s" str)
    1.62 +	    (let ((i 0) d)
    1.63 +	      (setq str (downcase str))
    1.64 +	      (while (string< "" str)
    1.65 +		(setq d (+ 0 (string-to-char str)) ; + 0 for XEmacs
    1.66 +		      i (+ (* 16 i) (- d (if (<= d ?9) ?0 (- ?a 10))))
    1.67 +		      str (substring str 1)))
    1.68 +	      i))
    1.69 +	(store-match-data md)))))
    1.70 +
    1.71 +
    1.72  ;;; Function for menu support
    1.73  (defun YaTeX-define-menu (keymap bindlist)
    1.74    "Define KEYMAP(symbol)'s menu-bindings according to BINDLIST.