yatex
diff yatexadd.el @ 462:c940797c19ad
href target of file should be untranslated before find-file
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Mon, 29 May 2017 09:10:44 +0859 |
parents | 7bf780961390 |
children | a4d49700b1c5 |
line diff
1.1 --- a/yatexadd.el Mon Mar 06 17:54:31 2017 +0859 1.2 +++ b/yatexadd.el Mon May 29 09:10:44 2017 +0859 1.3 @@ -1,6 +1,6 @@ 1.4 ;;; yatexadd.el --- YaTeX add-in functions -*- coding: sjis -*- 1.5 ;;; (c)1991-2017 by HIROSE Yuuji.[yuuji@yatex.org] 1.6 -;;; Last modified Mon Mar 6 08:52:37 2017 on firestorm 1.7 +;;; Last modified Tue Mar 7 09:30:50 2017 on firestorm 1.8 ;;; $Id$ 1.9 1.10 ;;; Code: 1.11 @@ -853,37 +853,39 @@ 1.12 "*ref補完で収集するセクショニングコマンドの下限レベル 1.13 YaTeX-sectioning-levelの数値で指定.") 1.14 1.15 -(defun YaTeX::ref-1 () 1.16 +(defun YaTeX::ref-1 (&optional nest-level) 1.17 ;; Sub-function of YaTeX::ref() for recursive call 1.18 ;; DO NOT CALL FROM OTHER FUNCTIONS but YaTeX:ref() 1.19 - (while (YaTeX-re-search-active-forward 1.20 - regexp ;;counter 1.21 - percent nil t) 1.22 + (setq nest-level (or nest-level 0)) 1.23 + (let ((labelleader (substring " " 0 nest-level)) 1.24 + label) 1.25 + (while (YaTeX-re-search-active-forward 1.26 + regexp ;;counter 1.27 + percent nil t) 1.28 ;(goto-char (match-beginning 0)) 1.29 - (setq e0 (match-end 0)) 1.30 - (cond 1.31 - ;; 1.32 - ;;2005/10/21 Skip it if predicate function returns nil 1.33 - ((and predf 1.34 - (let ((md (match-data))) 1.35 - (prog1 1.36 - (condition-case nil 1.37 - (not (funcall predf)) 1.38 - (error nil)) 1.39 - (store-match-data md))))) 1.40 - ((YaTeX-literal-p) nil) 1.41 - ((YaTeX-match-string 1) 1.42 - ;;if standard counter commands found 1.43 - (setq cmd (YaTeX-match-string 2) 1.44 - m0 (match-beginning 0)) 1.45 - (setq match-point (match-beginning 0)) 1.46 - (or initl 1.47 - (if (< p (point)) (setq initl lnum))) 1.48 + (setq e0 (match-end 0)) 1.49 (cond 1.50 - ;; In any case, variables e0 should be set 1.51 - ((and YaTeX-use-AMS-LaTeX 1.52 - (string-match YaTeX::ref-nestable-counter-regexp cmd)) 1.53 - (let (label) 1.54 + ;; 1.55 + ;;2005/10/21 Skip it if predicate function returns nil 1.56 + ((and predf 1.57 + (let ((md (match-data))) 1.58 + (prog1 1.59 + (condition-case nil 1.60 + (not (funcall predf)) 1.61 + (error nil)) 1.62 + (store-match-data md))))) 1.63 + ((YaTeX-literal-p) nil) 1.64 + ((YaTeX-match-string 1) 1.65 + ;;if standard counter commands found 1.66 + (setq cmd (YaTeX-match-string 2) 1.67 + m0 (match-beginning 0)) 1.68 + (setq match-point (match-beginning 0)) 1.69 + (or initl 1.70 + (if (< p (point)) (setq initl lnum))) 1.71 + (cond 1.72 + ;; In any case, variables e0 should be set 1.73 + ((and YaTeX-use-AMS-LaTeX 1.74 + (string-match YaTeX::ref-nestable-counter-regexp cmd)) 1.75 (skip-chars-forward "}") 1.76 (setq label (buffer-substring 1.77 (point) (min (+ 80 (point)) (point-max)))) 1.78 @@ -896,217 +898,219 @@ 1.79 (if (looking-at "\\\\label{\\([^}]+\\)}") 1.80 (setq label (format "(labe:%s)" (YaTeX-match-string 1)) 1.81 e0 (match-end 1))) 1.82 - (funcall output (format "--subequation--%s" label) e0 'eqn))) 1.83 - ((string-match mathenvs cmd) ;;if matches mathematical env 1.84 - (skip-chars-forward "}") 1.85 - (setq x (point) 1.86 - envname (substring 1.87 - cmd (match-beginning 0) (match-end 0))) 1.88 - (save-restriction 1.89 - (narrow-to-region 1.90 - m0 1.91 - (save-excursion 1.92 - (YaTeX-re-search-active-forward 1.93 - (setq endrx (format "%send{%s}" YaTeX-ec-regexp 1.94 - (regexp-quote envname))) 1.95 - percent nil t))) 1.96 - (catch 'scan 1.97 - (while (YaTeX-re-search-active-forward 1.98 - (concat 1.99 - "\\\\end{\\(" (regexp-quote envname) "\\)" ;;(1) 1.100 - "\\|\\\\\\(notag\\)" ;;2 1.101 - (if (string-match 1.102 - YaTeX::ref-mathenv-exp1-regexp cmd) 1.103 - "" "\\|\\(\\\\\\\\\\)$") ;;3 1.104 - ) 1.105 - percent nil t) 1.106 - (let*((quit (match-beginning 1)) 1.107 - (notag (match-beginning 2)) 1.108 - (newln (match-beginning 3)) 1.109 - (label ".......................") l2 1.110 - (e (point)) (m0 (match-beginning 0)) 1.111 - (ln (YaTeX-string-width label))) 1.112 - (cond 1.113 - (notag 1.114 - (YaTeX-re-search-active-forward 1.115 - "\\\\\\\\" percent nil 1) 1.116 - (setq x (point))) ;use x as \label search bound 1.117 - ((and newln ; `\\' found 1.118 - (not (equal (YaTeX-inner-environment) 1.119 - envname))) 1.120 - (YaTeX-end-of-environment) 1.121 - (goto-char (match-end 0))) 1.122 - (t 1.123 - (if (YaTeX-re-search-active-backward 1.124 - YaTeX::ref-labeling-regexp 1.125 - percent x t) 1.126 - ;; if \label{x} in math-expression, display it 1.127 - ;; because formula source is hard to recognize 1.128 - (progn 1.129 - (goto-char (match-end 0)) 1.130 - (setq l2 (format "\"label:%s\"" 1.131 - (buffer-substring 1.132 - (1- (point)) 1.133 - (progn (forward-sexp -1) 1.134 - (1+ (point)))))) 1.135 - (setq label 1.136 - (if (< (YaTeX-string-width l2) ln) 1.137 - (concat 1.138 - l2 1.139 - (substring 1.140 - label 1.141 - 0 (- ln (YaTeX-string-width l2)))) 1.142 - l2)) 1.143 - (goto-char e))) 1.144 - (funcall output 1.145 - (concat 1.146 - label " " 1.147 - (buffer-substring x m0)) 1.148 - x 'eqn) 1.149 + (funcall output 1.150 + (format "--subequation--%s%s" labelleader label) 1.151 + e0 'eqn)) 1.152 + ((string-match mathenvs cmd) ;;if matches mathematical env 1.153 + (skip-chars-forward "}") 1.154 + (setq x (point) 1.155 + envname (substring 1.156 + cmd (match-beginning 0) (match-end 0))) 1.157 + (save-restriction 1.158 + (narrow-to-region 1.159 + m0 1.160 + (save-excursion 1.161 + (YaTeX-re-search-active-forward 1.162 + (setq endrx (format "%send{%s}" YaTeX-ec-regexp 1.163 + (regexp-quote envname))) 1.164 + percent nil t))) 1.165 + (catch 'scan 1.166 + (while (YaTeX-re-search-active-forward 1.167 + (concat 1.168 + "\\\\end{\\(" (regexp-quote envname) "\\)" ;;(1) 1.169 + "\\|\\\\\\(notag\\)" ;;2 1.170 + (if (string-match 1.171 + YaTeX::ref-mathenv-exp1-regexp cmd) 1.172 + "" "\\|\\(\\\\\\\\\\)$") ;;3 1.173 + ) 1.174 + percent nil t) 1.175 + (let*((quit (match-beginning 1)) 1.176 + (notag (match-beginning 2)) 1.177 + (newln (match-beginning 3)) 1.178 + (label ".......................") l2 1.179 + (e (point)) (m0 (match-beginning 0)) 1.180 + (ln (YaTeX-string-width label))) 1.181 (cond 1.182 - ((YaTeX-quick-in-environment-p 1.183 - YaTeX-math-gathering-list) 1.184 - ;; if here is inner split/cases/gathered env., 1.185 - ;; counter for here is only one. 1.186 - ;; Go out this environment and, 1.187 + (notag 1.188 + (YaTeX-re-search-active-forward 1.189 + "\\\\\\\\" percent nil 1) 1.190 + (setq x (point))) ;use x as \label search bound 1.191 + ((and newln ; `\\' found 1.192 + (not (equal (YaTeX-inner-environment) 1.193 + envname))) 1.194 (YaTeX-end-of-environment) 1.195 - ;; search next expression unit boundary. 1.196 - (YaTeX-re-search-active-forward 1.197 - (concat endrx "\\|\\\\begin{") 1.198 - percent nil 1) 1.199 - (end-of-line))) 1.200 - (if quit (throw 'scan t))))) 1.201 - (setq x (point))))) 1.202 - (setq e0 (point))) 1.203 - ((string-match enums cmd) 1.204 + (goto-char (match-end 0))) 1.205 + (t 1.206 + (if (YaTeX-re-search-active-backward 1.207 + YaTeX::ref-labeling-regexp 1.208 + percent x t) 1.209 + ;; if \label{x} in math-expression, display it 1.210 + ;; because formula source is hard to recognize 1.211 + (progn 1.212 + (goto-char (match-end 0)) 1.213 + (setq l2 (format "\"label:%s\"" 1.214 + (buffer-substring 1.215 + (1- (point)) 1.216 + (progn (forward-sexp -1) 1.217 + (1+ (point)))))) 1.218 + (setq label 1.219 + (if (< (YaTeX-string-width l2) ln) 1.220 + (concat 1.221 + l2 1.222 + (substring 1.223 + label 1.224 + 0 (- ln (YaTeX-string-width l2)))) 1.225 + l2)) 1.226 + (goto-char e))) 1.227 + (funcall output 1.228 + (concat 1.229 + labelleader label " " 1.230 + (buffer-substring x m0)) 1.231 + x 'eqn) 1.232 + (cond 1.233 + ((YaTeX-quick-in-environment-p 1.234 + YaTeX-math-gathering-list) 1.235 + ;; if here is inner split/cases/gathered env., 1.236 + ;; counter for here is only one. 1.237 + ;; Go out this environment and, 1.238 + (YaTeX-end-of-environment) 1.239 + ;; search next expression unit boundary. 1.240 + (YaTeX-re-search-active-forward 1.241 + (concat endrx "\\|\\\\begin{") 1.242 + percent nil 1) 1.243 + (end-of-line))) 1.244 + (if quit (throw 'scan t))))) 1.245 + (setq x (point))))) 1.246 + (setq e0 (point))) 1.247 + ((string-match enums cmd) 1.248 ;(skip-chars-forward "} \t\n") 1.249 - (save-restriction 1.250 - (narrow-to-region 1.251 - (point) 1.252 - (save-excursion 1.253 - (YaTeX-goto-corresponding-environment nil t 'nonstop) (point))) 1.254 - (forward-line 1) 1.255 - (let ((b0 nil) mb0) 1.256 - (while (not (eobp)) 1.257 - (setq x (and 1.258 - (YaTeX-re-search-active-forward 1.259 - (concat YaTeX-ec-regexp "item\\s ") 1.260 - percent nil 1) 1.261 - (match-beginning 0))) 1.262 + (save-restriction 1.263 + (narrow-to-region 1.264 + (point) 1.265 + (save-excursion 1.266 + (YaTeX-goto-corresponding-environment nil t 'nonstop) (point))) 1.267 + (forward-line 1) 1.268 + (let ((b0 nil) mb0) 1.269 + (while (not (eobp)) 1.270 + (setq x (and 1.271 + (YaTeX-re-search-active-forward 1.272 + (concat YaTeX-ec-regexp "item\\s ") 1.273 + percent nil 1) 1.274 + (match-beginning 0))) 1.275 1.276 - (if b0 ;Inspect sentence after previous \item 1.277 - (save-excursion 1.278 - (save-restriction 1.279 - (let ((md (match-data))) ;save-match-data 1.280 - (unwind-protect 1.281 - (progn 1.282 - (narrow-to-region b0 (or x (point))) 1.283 - (goto-char (point-min)) 1.284 - (let ((x x)) (YaTeX::ref-1)) 1.285 - (goto-char (point-max))) 1.286 - (store-match-data md)))))) 1.287 - (if x ;Output THIS \item line 1.288 - (funcall 1.289 - output 1.290 - (concat 1.291 - existlabel 1.292 + (if b0 ;Inspect sentence after previous \item 1.293 + (save-excursion 1.294 + (save-restriction 1.295 + (let ((md (match-data))) ;save-match-data 1.296 + (unwind-protect 1.297 + (progn 1.298 + (narrow-to-region b0 (or x (point))) 1.299 + (goto-char (point-min)) 1.300 + (let ((x x)) (YaTeX::ref-1 (1+ nest-level))) 1.301 + (goto-char (point-max))) 1.302 + (store-match-data md)))))) 1.303 + (if x ;Output THIS \item line 1.304 + (funcall 1.305 + output 1.306 + (concat 1.307 + labelleader existlabel 1.308 + (buffer-substring 1.309 + (match-beginning 0) 1.310 + (if (re-search-forward itemsep nil 1) 1.311 + (progn (goto-char (match-beginning 0)) 1.312 + (skip-chars-backward " \t") 1.313 + (1- (point))) 1.314 + (point-end-of-line)))) 1.315 + x 'item)) 1.316 + (setq b0 (point)) 1.317 + )) 1.318 + (setq e0 (point-max)))) 1.319 + ((string-match "bibitem" cmd) ;maybe generated by myself 1.320 + (setq label "") 1.321 + (skip-chars-forward " \t") 1.322 + (if (looking-at "{") ;sure to be true!! 1.323 + (forward-list 1)) 1.324 + (let ((list '(30 10 65)) 1.325 + (delim ";") q lim len l str) 1.326 + (save-excursion 1.327 + (setq lim (if (re-search-forward itemsep nil 1) 1.328 + (match-beginning 0) (point)))) 1.329 + (while list 1.330 + (skip-chars-forward " \t\n\\") 1.331 + (setq q (looking-at "[\"'{]") 1.332 + len (car list) 1.333 + str 1.334 (buffer-substring 1.335 - (match-beginning 0) 1.336 - (if (re-search-forward itemsep nil 1) 1.337 - (progn (goto-char (match-beginning 0)) 1.338 - (skip-chars-backward " \t") 1.339 - (1- (point))) 1.340 - (point-end-of-line)))) 1.341 - x 'item)) 1.342 - (setq b0 (point)) 1.343 - )) 1.344 - (setq e0 (point-max)))) 1.345 - ((string-match "bibitem" cmd) ;maybe generated by myself 1.346 - (setq label "") 1.347 - (skip-chars-forward " \t") 1.348 - (if (looking-at "{") ;sure to be true!! 1.349 - (forward-list 1)) 1.350 - (let ((list '(30 10 65)) 1.351 - (delim ";") q lim len l str) 1.352 - (save-excursion 1.353 - (setq lim (if (re-search-forward itemsep nil 1) 1.354 - (match-beginning 0) (point)))) 1.355 + (point) 1.356 + (progn 1.357 + (if q (forward-sexp 1) 1.358 + (search-forward delim lim 1) 1.359 + (forward-char -1)) 1.360 + (point)))) 1.361 + (if (> (setq l (YaTeX-string-width str)) len) 1.362 + (setq str (concat 1.363 + (YaTeX-truncate-string-width 1.364 + str (- len (if q 5 4))) 1.365 + "... " 1.366 + (if q (substring str -1))))) 1.367 + (if (< (setq l (YaTeX-string-width str)) len) 1.368 + (setq str (concat str (make-string (- len l) ? )))) 1.369 + (if (looking-at delim) (goto-char (match-end 0))) 1.370 + (setq label (concat label " " str) 1.371 + list (cdr list))) 1.372 + (funcall output labelleader label match-point 'bib))) 1.373 + ;;else, simple section-type counter 1.374 + ((= (char-after (1- (point))) ?{) 1.375 + (setq label (buffer-substring 1.376 + (match-beginning 0) 1.377 + (progn (forward-char -1) 1.378 + (forward-list 1) 1.379 + (point)))) 1.380 + (funcall output labelleader label match-point 1.381 + (if (string-match "caption" cmd) 'cap 'sec)) 1.382 + ;; Skip preceding label if exists 1.383 + (if (YaTeX::ref-getset-label (current-buffer) match-point t) 1.384 + (goto-char (get 'YaTeX::ref-getset-label 'foundpoint))) 1.385 + (if (save-excursion 1.386 + (skip-chars-forward "\t \n") 1.387 + (looking-at YaTeX::ref-labeling-regexp)) 1.388 + (setq e0 (match-end 0)))) 1.389 + (t 1.390 + (skip-chars-forward " \t") 1.391 + (setq label (buffer-substring 1.392 + (match-beginning 0) 1.393 + (if (re-search-forward 1.394 + itemsep 1.395 + nil t) 1.396 + (progn 1.397 + (goto-char (match-beginning 0)) 1.398 + (skip-chars-backward " \t") 1.399 + (1- (point))) 1.400 + (point-end-of-line)))) 1.401 + (funcall output labelleader label match-point 'misc) 1.402 + (if (save-excursion 1.403 + (skip-chars-forward "\t \n") 1.404 + (looking-at YaTeX::ref-labeling-regexp)) 1.405 + (setq e0 (match-end 0))))) 1.406 + ) ;;put label buffer 1.407 + ;; 1.408 + ;; if user defined label found 1.409 + (t 1.410 + ;; memorize line number and label into property 1.411 + (goto-char (match-beginning 0)) 1.412 + (let ((list YaTeX::ref-labeling-regexp-alist) 1.413 + (cache (symbol-plist 'YaTeX::ref-labeling-regexp))) 1.414 (while list 1.415 - (skip-chars-forward " \t\n\\") 1.416 - (setq q (looking-at "[\"'{]") 1.417 - len (car list) 1.418 - str 1.419 - (buffer-substring 1.420 - (point) 1.421 - (progn 1.422 - (if q (forward-sexp 1) 1.423 - (search-forward delim lim 1) 1.424 - (forward-char -1)) 1.425 - (point)))) 1.426 - (if (> (setq l (YaTeX-string-width str)) len) 1.427 - (setq str (concat 1.428 - (YaTeX-truncate-string-width 1.429 - str (- len (if q 5 4))) 1.430 - "... " 1.431 - (if q (substring str -1))))) 1.432 - (if (< (setq l (YaTeX-string-width str)) len) 1.433 - (setq str (concat str (make-string (- len l) ? )))) 1.434 - (if (looking-at delim) (goto-char (match-end 0))) 1.435 - (setq label (concat label " " str) 1.436 - list (cdr list))) 1.437 - (funcall output label match-point 'bib))) 1.438 - ;;else, simple section-type counter 1.439 - ((= (char-after (1- (point))) ?{) 1.440 - (setq label (buffer-substring 1.441 - (match-beginning 0) 1.442 - (progn (forward-char -1) 1.443 - (forward-list 1) 1.444 - (point)))) 1.445 - (funcall output label match-point 1.446 - (if (string-match "caption" cmd) 'cap 'sec)) 1.447 - ;; Skip preceding label if exists 1.448 - (if (YaTeX::ref-getset-label (current-buffer) match-point t) 1.449 - (goto-char (get 'YaTeX::ref-getset-label 'foundpoint))) 1.450 - (if (save-excursion 1.451 - (skip-chars-forward "\t \n") 1.452 - (looking-at YaTeX::ref-labeling-regexp)) 1.453 - (setq e0 (match-end 0)))) 1.454 - (t 1.455 - (skip-chars-forward " \t") 1.456 - (setq label (buffer-substring 1.457 - (match-beginning 0) 1.458 - (if (re-search-forward 1.459 - itemsep 1.460 - nil t) 1.461 - (progn 1.462 - (goto-char (match-beginning 0)) 1.463 - (skip-chars-backward " \t") 1.464 - (1- (point))) 1.465 - (point-end-of-line)))) 1.466 - (funcall output label match-point 'misc) 1.467 - (if (save-excursion 1.468 - (skip-chars-forward "\t \n") 1.469 - (looking-at YaTeX::ref-labeling-regexp)) 1.470 - (setq e0 (match-end 0))))) 1.471 - ) ;;put label buffer 1.472 - ;; 1.473 - ;; if user defined label found 1.474 - (t 1.475 - ;; memorize line number and label into property 1.476 - (goto-char (match-beginning 0)) 1.477 - (let ((list YaTeX::ref-labeling-regexp-alist) 1.478 - (cache (symbol-plist 'YaTeX::ref-labeling-regexp))) 1.479 - (while list 1.480 - (if (looking-at (car (car list))) 1.481 - (progn 1.482 - (setq label (YaTeX-match-string 0)) 1.483 - (put 'YaTeX::ref-labeling-regexp lnum 1.484 - (YaTeX-match-string (cdr (car list)))) 1.485 - (funcall output label 0) ;;0 is dummy, never used 1.486 - (setq list nil))) 1.487 - (setq list (cdr list)))) 1.488 - )) 1.489 - (goto-char e0))) 1.490 + (if (looking-at (car (car list))) 1.491 + (progn 1.492 + (setq label (YaTeX-match-string 0)) 1.493 + (put 'YaTeX::ref-labeling-regexp lnum 1.494 + (YaTeX-match-string (cdr (car list)))) 1.495 + (funcall output labelleader label 0) ;;0 is dummy, never used 1.496 + (setq list nil))) 1.497 + (setq list (cdr list)))) 1.498 + )) 1.499 + (goto-char e0)))) 1.500 1.501 (defun YaTeX::ref (argp &optional labelcmd refcmd predf) 1.502 (setplist 'YaTeX::ref-labeling-regexp nil) ;erase memory cache