yatex

changeset 168:191cffccc912 dev

Replace all \ref{LABEL} when changing \label{LABEL}. Move YaTeX-yatex-buffer-list to yatexlib.el
author yuuji@gentei.org
date Wed, 16 Feb 2011 20:08:05 +0900
parents d891d7c6cd8e
children 0cb6c6a78e9e
files yatex.el yatex.new yatexadd.el yatexlib.el
diffstat 4 files changed, 117 insertions(+), 18 deletions(-) [+]
line diff
     1.1 --- a/yatex.el	Mon Feb 14 14:50:33 2011 +0900
     1.2 +++ b/yatex.el	Wed Feb 16 20:08:05 2011 +0900
     1.3 @@ -1,15 +1,15 @@
     1.4  ;;; -*- Emacs-Lisp -*-
     1.5  ;;; Yet Another tex-mode for emacs - //野鳥//
     1.6 -;;; yatex.el rev. 1.74.3
     1.7 +;;; yatex.el rev. 1.74.4
     1.8  ;;; (c)1991-2011 by HIROSE Yuuji.[yuuji@yatex.org]
     1.9 -;;; Last modified Mon Feb 14 12:48:33 2011 on firestorm
    1.10 +;;; Last modified Wed Feb 16 17:23:52 2011 on firestorm
    1.11  ;;; $Id$
    1.12  ;;; The latest version of this software is always available at;
    1.13  ;;; http://www.yatex.org/
    1.14  
    1.15  (require 'comment)
    1.16  (require 'yatexlib)
    1.17 -(defconst YaTeX-revision-number "1.74.3"
    1.18 +(defconst YaTeX-revision-number "1.74.4"
    1.19    "Revision number of running yatex.el")
    1.20  
    1.21  ;---------- Local variables ----------
    1.22 @@ -1528,6 +1528,29 @@
    1.23  	(set-marker e nil))
    1.24         ))))
    1.25  
    1.26 +(defvar YaTeX-refcommand-def-regexp-default
    1.27 +  "label\\|bibitem")
    1.28 +(defvar YaTeX-refcommand-def-regexp-private nil
    1.29 +  "*Regexp of defining label commands")
    1.30 +(defvar YaTeX-refcommand-def-regexp
    1.31 +  (concat (if YaTeX-refcommand-def-regexp-private
    1.32 +	      (concat YaTeX-refcommand-def-regexp-private "\\|"))
    1.33 +	  YaTeX-refcommand-def-regexp-default))
    1.34 +
    1.35 +(defvar YaTeX-refcommand-ref-regexp-default
    1.36 +  "\\(page\\|eq\\|fig\\)?ref\\|cite")
    1.37 +(defvar YaTeX-refcommand-ref-regexp-private nil
    1.38 +  "*Regexp of referring label commands")
    1.39 +(defvar YaTeX-refcommand-ref-regexp
    1.40 +  (concat (if YaTeX-refcommand-ref-regexp-private
    1.41 +	      (concat YaTeX-refcommand-ref-regexp-private "\\|"))
    1.42 +	  YaTeX-refcommand-ref-regexp-default))
    1.43 +
    1.44 +(defvar YaTeX-refcommand-regexp
    1.45 +  (concat YaTeX-refcommand-def-regexp
    1.46 +	  "\\|" YaTeX-refcommand-ref-regexp)
    1.47 +  "Regexp of label defining/referring command name.")
    1.48 +
    1.49  (defun YaTeX-goto-corresponding-label (reverse &optional otherwin)
    1.50    "Jump to corresponding \\label{} and \\ref{} or \\cite and \\bibitem.
    1.51    The default search direction depends on the command at the cursor position.
    1.52 @@ -1543,7 +1566,7 @@
    1.53    If optional second argument OTHERWIN is non-nil, move to other window."
    1.54  
    1.55    (let ((scmd "") label direc string blist (p (point)) (cb (current-buffer))
    1.56 -	(refcommands "label\\|\\(page\\|eq\\)?ref\\|cite\\|bibitem")
    1.57 +	(refcommands YaTeX-refcommand-regexp)
    1.58  	(foundmsg (format "Type %s %c to return to original position."
    1.59  			  (key-description
    1.60  			   (car
     2.1 --- a/yatex.new	Mon Feb 14 14:50:33 2011 +0900
     2.2 +++ b/yatex.new	Wed Feb 16 20:08:05 2011 +0900
     2.3 @@ -5,7 +5,8 @@
     2.4  	[prefix] t e でポイント位置を含む環境か数式環境をタイプセット。
     2.5  	M-C-SPC で環境だけでなく数式環境もマークする。
     2.6  	[prefix] t d でタイプセッタ起動成功のあと dvipdfmx を起動。
     2.7 -	\label{}でラベル名を入れたときは \ref{NAME} を自動的にkill-ring追加。
     2.8 +	\label{}でラベル名を入れたときは \ref{NAME} を自動的にkill-ringに追加。
     2.9 +	\bibitem{}を入れたときは \cite{TAG} を自動的にkill-ringに追加。
    2.10  	=== yahtml ===
    2.11  	[prefix] t ブラウザメニューに「n:新規ページ作成」を追加(実験)。
    2.12  	[prefix] t j のlintコマンドを <!-- #lint CmdLine --> 行で指定可。
     3.1 --- a/yatexadd.el	Mon Feb 14 14:50:33 2011 +0900
     3.2 +++ b/yatexadd.el	Wed Feb 16 20:08:05 2011 +0900
     3.3 @@ -2,7 +2,7 @@
     3.4  ;;; YaTeX add-in functions.
     3.5  ;;; yatexadd.el rev.19
     3.6  ;;; (c)1991-2011 by HIROSE Yuuji.[yuuji@yatex.org]
     3.7 -;;; Last modified Mon Feb 14 14:48:30 2011 on firestorm
     3.8 +;;; Last modified Wed Feb 16 19:57:26 2011 on firestorm
     3.9  ;;; $Id$
    3.10  
    3.11  ;;;
    3.12 @@ -742,7 +742,7 @@
    3.13    "Alist of labeling regexp vs. its group number points to label string.
    3.14  This alist is used in \\ref's argument's completion.")
    3.15  (defvar YaTeX::ref-labeling-regexp-alist-private nil
    3.16 -  "*Private extesion to YaTeX::ref-labeling-regexp-alist.
    3.17 +  "*Private extension to YaTeX::ref-labeling-regexp-alist.
    3.18  See the documetation of YaTeX::ref-labeling-regexp-alist.")
    3.19  (defvar YaTeX::ref-labeling-regexp-alist
    3.20    (append YaTeX::ref-labeling-regexp-alist-default
    3.21 @@ -1119,12 +1119,86 @@
    3.22  	    (bury-buffer YaTeX-label-buffer)))
    3.23  	label)))))
    3.24  
    3.25 +(defun YaTeX::label-rename-refs (old new &optional def ref)
    3.26 +  "Rename reference tag from OLD to NEW.
    3.27 +Optional arguments DEF and REF specify defining command and
    3.28 +referring command respectively.
    3.29 +---------------------------------------------------------
    3.30 +CONTROL KEYS - キーの説明
    3.31 + y	Replace			置換する
    3.32 + n	Do not replace		置換しない
    3.33 + !	Replace All w/o query	残る全部を確認なしで置換
    3.34 + r	Enter Recursive-edit	再帰編集モードへ
    3.35 + q	Quit from replacing	ここまでで置換をやめる
    3.36 +
    3.37 +Don't forget to exit from recursive edit by typing \\[exit-recursive-edit]
    3.38 +再帰編集に入ったら \\[exit-recursive-edit]  で抜け忘れなきよう。"
    3.39 +  (save-window-excursion
    3.40 +    (catch 'exit
    3.41 +      (let*((bufs (YaTeX-yatex-buffer-list)) buf b e
    3.42 +	    (oldptn (regexp-quote old))
    3.43 +	    (sw (selected-window))
    3.44 +	    (ptn (concat
    3.45 +		  "\\(" YaTeX-refcommand-ref-regexp "\\)"
    3.46 +		  "\\s *{" oldptn "}"))
    3.47 +	    (useov (fboundp 'make-overlay)) ov
    3.48 +	    (qmsg "Replace to `%s'? [yn!rq]")
    3.49 +	    continue ch)
    3.50 +	(while bufs
    3.51 +	  (set-buffer (setq buf (car bufs)))
    3.52 +	  (save-excursion
    3.53 +	    (goto-char (point-min))
    3.54 +	    (while (re-search-forward ptn nil t)
    3.55 +	      (goto-char (match-end 1))
    3.56 +	      (skip-chars-forward " \t\n{")
    3.57 +	      (unwind-protect
    3.58 +		  (if (and
    3.59 +		       (looking-at oldptn)
    3.60 +		       (setq b (match-beginning 0)
    3.61 +			     e (match-end 0))
    3.62 +		       (or continue
    3.63 +			   (catch 'query
    3.64 +			     (if useov
    3.65 +				 (if ov (move-overlay ov b e)
    3.66 +				   (overlay-put
    3.67 +				    (setq ov (make-overlay b e))
    3.68 +				    'face 'isearch)))
    3.69 +			     (switch-to-buffer buf)
    3.70 +			     (while t
    3.71 +			       (message qmsg new)
    3.72 +			       (setq ch (read-char))
    3.73 +			       (cond
    3.74 +				((= ch ?q) (throw 'exit t))
    3.75 +				((= ch ?r)
    3.76 +				 (message
    3.77 +				  "Exit recursive-edit by `%s'"
    3.78 +				  (key-description
    3.79 +				   (where-is-internal
    3.80 +				    'exit-recursive-edit '(keymap) t)))
    3.81 +				 (sleep-for 2)
    3.82 +				 (recursive-edit))
    3.83 +				((= ch ?y) (throw 'query t))
    3.84 +				((= ch ?!) (throw 'query (setq continue t)))
    3.85 +				((= ch ??)
    3.86 +				 (describe-function
    3.87 +				  'YaTeX::label-rename-refs)
    3.88 +				 (select-window (get-buffer-window "*Help*"))
    3.89 +				 (search-forward "----")
    3.90 +				 (forward-line 1)
    3.91 +				 (set-window-start (selected-window) (point))
    3.92 +				 (sit-for 0)
    3.93 +				 (select-window sw))
    3.94 +				((= ch ?n) (throw 'query nil)))))))
    3.95 +		      (replace-match new))
    3.96 +		(and ov (delete-overlay ov)))))
    3.97 +	  (setq bufs (cdr bufs)))))))
    3.98 +
    3.99  (defun YaTeX::label (argp &optional labname refname)
   3.100    "Read label name and return it with copying \\ref{LABEL-NAME} to kill-ring."
   3.101    (cond
   3.102     ((= argp 1)
   3.103 -    (let*((dlab (if (boundp (intern-soft "old"))
   3.104 -		    old ;if called via YaTeX-change-section (tricky...)
   3.105 +    (let*((chmode (boundp (intern-soft "old")))
   3.106 +	  (dlab (if chmode old ;if called via YaTeX-change-section (tricky...)
   3.107  		  (YaTeX::ref-default-label)))
   3.108  	  (label (read-string
   3.109  		  (format "New %s name: " (or labname "label"))
   3.110 @@ -1137,7 +1211,8 @@
   3.111  		     "をkill-ringに入れました。yank(%s)で取り出せます。"
   3.112  		   " is stored into kill-ring.  Paste it by yank(%s).")))
   3.113  	    (kill-new refstr)
   3.114 -	    (message (concat "`%s'" msg) refstr key)))
   3.115 +	    (message (concat "`%s'" msg) refstr key)
   3.116 +	    (if chmode (YaTeX::label-rename-refs old label))))
   3.117        label))))
   3.118        
   3.119  
   3.120 @@ -1322,13 +1397,6 @@
   3.121  (fset 'YaTeX::citep 'YaTeX::cite)
   3.122  (fset 'YaTeX::citet 'YaTeX::cite)
   3.123  
   3.124 -(defun YaTeX-yatex-buffer-list ()
   3.125 -  (save-excursion
   3.126 -    (delq nil (mapcar (function (lambda (buf)
   3.127 -				  (set-buffer buf)
   3.128 -				  (if (eq major-mode 'yatex-mode) buf)))
   3.129 -		      (buffer-list)))))
   3.130 -
   3.131  (defun YaTeX-select-other-yatex-buffer ()
   3.132    "Select buffer from all yatex-mode's buffers interactivelly."
   3.133    (interactive)
     4.1 --- a/yatexlib.el	Mon Feb 14 14:50:33 2011 +0900
     4.2 +++ b/yatexlib.el	Wed Feb 16 20:08:05 2011 +0900
     4.3 @@ -2,7 +2,7 @@
     4.4  ;;; YaTeX and yahtml common libraries, general functions and definitions
     4.5  ;;; yatexlib.el
     4.6  ;;; (c)1994-2009 by HIROSE Yuuji.[yuuji@yatex.org]
     4.7 -;;; Last modified Sat Sep 11 11:40:11 2010 on firestorm
     4.8 +;;; Last modified Wed Feb 16 19:58:33 2011 on firestorm
     4.9  ;;; $Id$
    4.10  
    4.11  ;; General variables
    4.12 @@ -665,6 +665,13 @@
    4.13      (self-insert-command 1)
    4.14      (YaTeX-minibuffer-complete)))
    4.15  
    4.16 +(defun YaTeX-yatex-buffer-list ()
    4.17 +  (save-excursion
    4.18 +    (delq nil (mapcar (function (lambda (buf)
    4.19 +				  (set-buffer buf)
    4.20 +				  (if (eq major-mode 'yatex-mode) buf)))
    4.21 +		      (buffer-list)))))
    4.22 +
    4.23  (defun foreach-buffers (pattern job)
    4.24    "For each buffer which matches with PATTERN, do JOB."
    4.25    (let ((list (buffer-list)))