# HG changeset patch # User HIROSE Yuuji # Date 1487720886 -32373 # Node ID aaa655456752908b1ddb23a714e1405ab3879715 # Parent f38293cfe5083724961140e1e668f307f05e4ee5 Label completion filter by M-c, M-e, M-i, M-s, M-m diff -r f38293cfe508 -r aaa655456752 yatex.new --- a/yatex.new Tue Feb 21 19:57:32 2017 +0859 +++ b/yatex.new Wed Feb 22 08:47:39 2017 +0859 @@ -1,6 +1,10 @@ What's new in YaTeX/yahtml 野鳥/yahtml - 各バージョンの変更点について +1.80 string-to-int除外と同時に emacs-18 をサポート外に。 + == yatex == + ラベル補完バッファで M-e, M-i 等でラベル種の絞り込み可能。 + 1.79 別フレームに同一バッファがあるときのミニバッファ入力で、 ポイント位置がずれるEmacsの問題への対策を入れた。 === yatex === diff -r f38293cfe508 -r aaa655456752 yatexadd.el --- a/yatexadd.el Tue Feb 21 19:57:32 2017 +0859 +++ b/yatexadd.el Wed Feb 22 08:47:39 2017 +0859 @@ -1,6 +1,6 @@ ;;; yatexadd.el --- YaTeX add-in functions -*- coding: sjis -*- ;;; (c)1991-2017 by HIROSE Yuuji.[yuuji@yatex.org] -;;; Last modified Thu Jan 5 23:13:23 2017 on firestorm +;;; Last modified Wed Feb 22 08:17:25 2017 on firestorm ;;; $Id$ ;;; Code: @@ -404,11 +404,12 @@ (defvar YaTeX-label-menu-other (if YaTeX-japan "':他のバッファのラベル\n" "':LABEL IN OTHER BUFFER.\n")) (defvar YaTeX-label-menu-repeat - (if YaTeX-japan ".:直前の\\refと同じ\n" "/:REPEAT LAST \ref{}\n")) + (if YaTeX-japan ".:直前の\\refと同じ\n" ".:REPEAT LAST \\ref{}\n")) (defvar YaTeX-label-menu-any (if YaTeX-japan "*:任意の文字列\n" "*:ANY STRING.\n")) (defvar YaTeX-label-buffer "*Label completions*") -(defvar YaTeX-label-guide-msg "Select label and hit RETURN.") +(defvar YaTeX-label-guide-msg + "[RET] on the Label. M-a)All M-c)Capt M-e)Eqn M-i)Itm M-s)Sec M-m)misc") (defvar YaTeX-label-select-map nil "Key map used in label selection buffer.") (defun YaTeX::label-setup-key-map () @@ -434,6 +435,12 @@ (define-key YaTeX-label-select-map "'" 'YaTeX::label-search-tag) (define-key YaTeX-label-select-map "." 'YaTeX::label-search-tag) (define-key YaTeX-label-select-map "*" 'YaTeX::label-search-tag) + (define-key YaTeX-label-select-map "\M-a" 'YaTeX::label-sel-all) + (define-key YaTeX-label-select-map "\M-c" 'YaTeX::label-sel-cap) + (define-key YaTeX-label-select-map "\M-e" 'YaTeX::label-sel-eqn) + (define-key YaTeX-label-select-map "\M-i" 'YaTeX::label-sel-item) + (define-key YaTeX-label-select-map "\M-s" 'YaTeX::label-sel-sec) + (define-key YaTeX-label-select-map "\M-m" 'YaTeX::label-sel-misc) (message "Setting up label selection mode map...Done") (let ((key ?A)) (while (<= key ?Z) @@ -462,6 +469,38 @@ (goto-char (match-beginning 0)))) (message YaTeX-label-guide-msg))) +(defun YaTeX::label-sel-* (type &optional any) + "Label type filtering out in YaTeX Label completion buffer" + (save-excursion + (let (ov) + (goto-char (point-min)) + (while (not (eobp)) + (goto-char (next-overlay-change (point))) + (if (null (setq ov (car-safe (overlays-at (point))))) + nil ;do nothin if overlays not found + (overlay-put + ov 'invisible (not (or any + (eq (overlay-get ov 'type) type))))))))) + +(defun YaTeX::label-sel-all () + (interactive) + (YaTeX::label-sel-* 'any 'any)) +(defun YaTeX::label-sel-cap () + (interactive) + (YaTeX::label-sel-* 'cap)) +(defun YaTeX::label-sel-eqn () + (interactive) + (YaTeX::label-sel-* 'eqn)) +(defun YaTeX::label-sel-item () + (interactive) + (YaTeX::label-sel-* 'item)) +(defun YaTeX::label-sel-sec () + (interactive) + (YaTeX::label-sel-* 'sec)) +(defun YaTeX::label-sel-misc () + (interactive) + (YaTeX::label-sel-* 'misc)) + ; (defun YaTeX::ref (argp &optional labelcmd refcmd) ; (cond ; ((= argp 1) @@ -680,7 +719,7 @@ (if (condition-case nil (progn (goto-char curtop) - (YaTeX-goto-corresponding-environment)) + (YaTeX-goto-corresponding-environment nil t 'nonstop)) (error nil)) (setq end (point))) (goto-char inspoint) @@ -814,6 +853,261 @@ "*ref補完で収集するセクショニングコマンドの下限レベル YaTeX-sectioning-levelの数値で指定.") +(defun YaTeX::ref-1 () + ;; Sub-function of YaTeX::ref() for recursive call + ;; DO NOT CALL FROM OTHER FUNCTIONS but YaTeX:ref() + (while (YaTeX-re-search-active-forward + regexp ;;counter + percent nil t) + ;(goto-char (match-beginning 0)) + (setq e0 (match-end 0)) + (cond + ;; + ;;2005/10/21 Skip it if predicate function returns nil + ((and predf + (let ((md (match-data))) + (prog1 + (condition-case nil + (not (funcall predf)) + (error nil)) + (store-match-data md))))) + ((YaTeX-literal-p) nil) + ((YaTeX-match-string 1) + ;;if standard counter commands found + (setq cmd (YaTeX-match-string 2) + m0 (match-beginning 0)) + (setq match-point (match-beginning 0)) + (or initl + (if (< p (point)) (setq initl lnum))) + (cond + ;; In any case, variables e0 should be set + ((and YaTeX-use-AMS-LaTeX + (string-match YaTeX::ref-nestable-counter-regexp cmd)) + (let (label) + (skip-chars-forward "}") + (setq label (buffer-substring + (point) (min (+ 80 (point)) (point-max)))) + ;; to skip (maybe)auto-generated comment + (skip-chars-forward " \t") + (if (looking-at YaTeX-comment-prefix) + (forward-line 1)) + (setq e0 (point)) + (skip-chars-forward " \t\n") + (if (looking-at "\\\\label{\\([^}]+\\)}") + (setq label (format "(labe:%s)" (YaTeX-match-string 1)) + e0 (match-end 1))) + (funcall output (format "--subequation--%s" label) e0 'eqn))) + ((string-match mathenvs cmd) ;;if matches mathematical env + (skip-chars-forward "}") + (setq x (point) + envname (substring + cmd (match-beginning 0) (match-end 0))) + (save-restriction + (narrow-to-region + m0 + (save-excursion + (YaTeX-re-search-active-forward + (setq endrx (format "%send{%s}" YaTeX-ec-regexp + (regexp-quote envname))) + percent nil t))) + (catch 'scan + (while (YaTeX-re-search-active-forward + (concat + "\\\\end{\\(" (regexp-quote envname) "\\)" ;;(1) + "\\|\\\\\\(notag\\)" ;;2 + (if (string-match + YaTeX::ref-mathenv-exp1-regexp cmd) + "" "\\|\\(\\\\\\\\\\)$") ;;3 + ) + percent nil t) + (let*((quit (match-beginning 1)) + (notag (match-beginning 2)) + (newln (match-beginning 3)) + (label ".......................") l2 + (e (point)) (m0 (match-beginning 0)) + (ln (YaTeX-string-width label))) + (cond + (notag + (YaTeX-re-search-active-forward + "\\\\\\\\" percent nil 1) + (setq x (point))) ;use x as \label search bound + ((and newln ; `\\' found + (not (equal (YaTeX-inner-environment) + envname))) + (YaTeX-end-of-environment) + (goto-char (match-end 0))) + (t + (if (YaTeX-re-search-active-backward + YaTeX::ref-labeling-regexp + percent x t) + ;; if \label{x} in math-expression, display it + ;; because formula source is hard to recognize + (progn + (goto-char (match-end 0)) + (setq l2 (format "\"label:%s\"" + (buffer-substring + (1- (point)) + (progn (forward-sexp -1) + (1+ (point)))))) + (setq label + (if (< (YaTeX-string-width l2) ln) + (concat + l2 + (substring + label + 0 (- ln (YaTeX-string-width l2)))) + l2)) + (goto-char e))) + (funcall output + (concat + label " " + (buffer-substring x m0)) + x 'eqn) + (cond + ((YaTeX-quick-in-environment-p + YaTeX-math-gathering-list) + ;; if here is inner split/cases/gathered env., + ;; counter for here is only one. + ;; Go out this environment and, + (YaTeX-end-of-environment) + ;; search next expression unit boundary. + (YaTeX-re-search-active-forward + (concat endrx "\\|\\\\begin{") + percent nil 1) + (end-of-line))) + (if quit (throw 'scan t))))) + (setq x (point))))) + (setq e0 (point))) + ((string-match enums cmd) + ;(skip-chars-forward "} \t\n") + (save-restriction + (narrow-to-region + (point) + (save-excursion + (YaTeX-goto-corresponding-environment nil t 'nonstop) (point))) + (forward-line 1) + (let ((b0 nil) mb0) + (while (not (eobp)) + (setq x (and + (YaTeX-re-search-active-forward + (concat YaTeX-ec-regexp "item\\s ") + percent nil 1) + (match-beginning 0))) + + (if b0 ;Inspect sentence after previous \item + (save-excursion + (save-restriction + (let ((md (match-data))) ;save-match-data + (unwind-protect + (progn + (narrow-to-region b0 (or x (point))) + (goto-char (point-min)) + (let ((x x)) (YaTeX::ref-1)) + (goto-char (point-max))) + (store-match-data md)))))) + (if x ;Output THIS \item line + (funcall + output + (concat + existlabel + (buffer-substring + (match-beginning 0) + (if (re-search-forward itemsep nil t) + (progn (goto-char (match-beginning 0)) + (skip-chars-backward " \t") + (1- (point))) + (point-end-of-line)))) + x 'item)) + (setq b0 (point)) + )) + (setq e0 (point-max)))) + ((string-match "bibitem" cmd) ;maybe generated by myself + (setq label "") + (skip-chars-forward " \t") + (if (looking-at "{") ;sure to be true!! + (forward-list 1)) + (let ((list '(30 10 65)) + (delim ";") q lim len l str) + (save-excursion + (setq lim (if (re-search-forward itemsep nil 1) + (match-beginning 0) (point)))) + (while list + (skip-chars-forward " \t\n\\") + (setq q (looking-at "[\"'{]") + len (car list) + str + (buffer-substring + (point) + (progn + (if q (forward-sexp 1) + (search-forward delim lim 1) + (forward-char -1)) + (point)))) + (if (> (setq l (YaTeX-string-width str)) len) + (setq str (concat + (YaTeX-truncate-string-width + str (- len (if q 5 4))) + "... " + (if q (substring str -1))))) + (if (< (setq l (YaTeX-string-width str)) len) + (setq str (concat str (make-string (- len l) ? )))) + (if (looking-at delim) (goto-char (match-end 0))) + (setq label (concat label " " str) + list (cdr list))) + (funcall output label match-point 'bib))) + ;;else, simple section-type counter + ((= (char-after (1- (point))) ?{) + (setq label (buffer-substring + (match-beginning 0) + (progn (forward-char -1) + (forward-list 1) + (point)))) + (funcall output label match-point + (if (string-match "caption" cmd) 'cap 'sec)) + ;; Skip preceding label if exists + (if (YaTeX::ref-getset-label (current-buffer) match-point t) + (goto-char (get 'YaTeX::ref-getset-label 'foundpoint))) + (if (save-excursion + (skip-chars-forward "\t \n") + (looking-at YaTeX::ref-labeling-regexp)) + (setq e0 (match-end 0)))) + (t + (skip-chars-forward " \t") + (setq label (buffer-substring + (match-beginning 0) + (if (re-search-forward + itemsep + nil t) + (progn + (goto-char (match-beginning 0)) + (skip-chars-backward " \t") + (1- (point))) + (point-end-of-line)))) + (funcall output label match-point 'misc) + (if (save-excursion + (skip-chars-forward "\t \n") + (looking-at YaTeX::ref-labeling-regexp)) + (setq e0 (match-end 0))))) + ) ;;put label buffer + ;; + ;; if user defined label found + (t + ;; memorize line number and label into property + (goto-char (match-beginning 0)) + (let ((list YaTeX::ref-labeling-regexp-alist) + (cache (symbol-plist 'YaTeX::ref-labeling-regexp))) + (while list + (if (looking-at (car (car list))) + (progn + (setq label (YaTeX-match-string 0)) + (put 'YaTeX::ref-labeling-regexp lnum + (YaTeX-match-string (cdr (car list)))) + (funcall output label 0) ;;0 is dummy, never used + (setq list nil))) + (setq list (cdr list)))) + )) + (goto-char e0))) + (defun YaTeX::ref (argp &optional labelcmd refcmd predf) (setplist 'YaTeX::ref-labeling-regexp nil) ;erase memory cache (require 'yatexsec) @@ -854,14 +1148,22 @@ (percent (regexp-quote YaTeX-comment-prefix)) (output (function - (lambda (label p) + (lambda (label p &optional type) ;type: 'eqn 'item 'cap 'sec 'misc (while (setq x (string-match "[\n\t]" label)) (aset label x ? )) (while (setq x (string-match " +" label)) (setq label (concat (substring label 0 (1+ (match-beginning 0))) (substring label (match-end 0))))) - (princ (format "%c: <<%s>>\n" (+ (% lnum 26) ?A) label)) + (save-excursion + (set-buffer standard-output) + (overlay-put + (make-overlay + (point) + (progn + (insert (format "%c: <<%s>>\n" (+ (% lnum 26) ?A) label)) + (point))) + 'type type)) (setq point-list (cons p point-list)) (message "Collecting labels... %d" lnum) (setq lnum (1+ lnum))))) @@ -890,238 +1192,10 @@ (goto-char (point-min)) (let ((standard-output (get-buffer YaTeX-label-buffer)) existlabel) (princ (format "=== LABELS in [%s] ===\n" (buffer-name buf))) - (while (YaTeX-re-search-active-forward - regexp ;;counter - percent nil t) - ;(goto-char (match-beginning 0)) - (setq e0 (match-end 0)) - (cond - ;; - ;;2005/10/21 Skip it if predicate function returns nil - ((and predf - (let ((md (match-data))) - (prog1 - (condition-case nil - (not (funcall predf)) - (error nil)) - (store-match-data md))))) - ((YaTeX-literal-p) nil) - ((YaTeX-match-string 1) - ;;if standard counter commands found - (setq cmd (YaTeX-match-string 2) - m0 (match-beginning 0)) - (setq match-point (match-beginning 0)) - (or initl - (if (< p (point)) (setq initl lnum))) - (cond - ;; In any case, variables e0 should be set - ((and YaTeX-use-AMS-LaTeX - (string-match YaTeX::ref-nestable-counter-regexp cmd)) - (let (label) - (skip-chars-forward "}") - (setq label (buffer-substring - (point) (min (+ 80 (point)) (point-max)))) - ;; to skip (maybe)auto-generated comment - (skip-chars-forward " \t") - (if (looking-at YaTeX-comment-prefix) - (forward-line 1)) - (setq e0 (point)) - (skip-chars-forward " \t\n") - (if (looking-at "\\\\label{\\([^}]+\\)}") - (setq label (format "(labe:%s)" (YaTeX-match-string 1)) - e0 (match-end 1))) - (funcall output (format "--subequation--%s" label) e0))) - ((string-match mathenvs cmd) ;;if matches mathematical env - (skip-chars-forward "}") - (setq x (point) - envname (substring - cmd (match-beginning 0) (match-end 0))) - (save-restriction - (narrow-to-region - m0 - (save-excursion - (YaTeX-re-search-active-forward - (setq endrx (format "%send{%s}" YaTeX-ec-regexp - (regexp-quote envname))) - percent nil t))) - (catch 'scan - (while (YaTeX-re-search-active-forward - (concat - "\\\\end{\\(" (regexp-quote envname) "\\)";;(1) - "\\|\\\\\\(notag\\)" ;;2 - (if (string-match - YaTeX::ref-mathenv-exp1-regexp cmd) - "" "\\|\\(\\\\\\\\\\)$") ;;3 - ) - percent nil t) - (let*((quit (match-beginning 1)) - (notag (match-beginning 2)) - (newln (match-beginning 3)) - (label ".......................") l2 - (e (point)) (m0 (match-beginning 0)) - (ln (YaTeX-string-width label))) - (cond - (notag - (YaTeX-re-search-active-forward - "\\\\\\\\" percent nil 1) - (setq x (point))) ;use x as \label search bound - ((and newln ; `\\' found - (not (equal (YaTeX-inner-environment) - envname))) - (YaTeX-end-of-environment) - (goto-char (match-end 0))) - (t - (if (YaTeX-re-search-active-backward - YaTeX::ref-labeling-regexp - percent x t) - ;; if \label{x} in math-expression, display it - ;; because formula source is hard to recognize - (progn - (goto-char (match-end 0)) - (setq l2 (format "\"label:%s\"" - (buffer-substring - (1- (point)) - (progn (forward-sexp -1) - (1+ (point)))))) - (setq label - (if (< (YaTeX-string-width l2) ln) - (concat - l2 - (substring - label - 0 (- ln (YaTeX-string-width l2)))) - l2)) - (goto-char e))) - (funcall output - (concat - label " " - (buffer-substring x m0)) - x) - (cond - ((YaTeX-quick-in-environment-p - YaTeX-math-gathering-list) - ;; if here is inner split/cases/gathered env., - ;; counter for here is only one. - ;; Go out this environment and, - (YaTeX-end-of-environment) - ;; search next expression unit boundary. - (YaTeX-re-search-active-forward - (concat endrx "\\|\\\\begin{") - percent nil 1) - (end-of-line))) - (if quit (throw 'scan t))))) - (setq x (point))))) - (setq e0 (point))) - ((string-match enums cmd) - ;(skip-chars-forward "} \t\n") - (save-restriction - (narrow-to-region - (point) - (save-excursion - (YaTeX-goto-corresponding-environment) (point))) - (forward-line 1) - (while (YaTeX-re-search-active-forward - (concat YaTeX-ec-regexp "item\\s ") - percent nil t) - (setq x (match-beginning 0)) - (funcall - output - (concat - existlabel - (buffer-substring - (match-beginning 0) - (if (re-search-forward itemsep nil t) - (progn (goto-char (match-beginning 0)) - (skip-chars-backward " \t") - (1- (point))) - (point-end-of-line)))) - x)) - (setq e0 (point-max)))) - ((string-match "bibitem" cmd) ;maybe generated by myself - (setq label "") - (skip-chars-forward " \t") - (if (looking-at "{") ;sure to be true!! - (forward-list 1)) - (let ((list '(30 10 65)) - (delim ";") q lim len l str) - (save-excursion - (setq lim (if (re-search-forward itemsep nil 1) - (match-beginning 0) (point)))) - (while list - (skip-chars-forward " \t\n\\") - (setq q (looking-at "[\"'{]") - len (car list) - str - (buffer-substring - (point) - (progn - (if q (forward-sexp 1) - (search-forward delim lim 1) - (forward-char -1)) - (point)))) - (if (> (setq l (YaTeX-string-width str)) len) - (setq str (concat - (YaTeX-truncate-string-width - str (- len (if q 5 4))) - "... " - (if q (substring str -1))))) - (if (< (setq l (YaTeX-string-width str)) len) - (setq str (concat str (make-string (- len l) ? )))) - (if (looking-at delim) (goto-char (match-end 0))) - (setq label (concat label " " str) - list (cdr list))) - (funcall output label match-point))) - ;;else, simple section-type counter - ((= (char-after (1- (point))) ?{) - (setq label (buffer-substring - (match-beginning 0) - (progn (forward-char -1) - (forward-list 1) - (point)))) - (funcall output label match-point) - ;; Skip preceding label if exists - (if (YaTeX::ref-getset-label (current-buffer) match-point t) - (goto-char (get 'YaTeX::ref-getset-label 'foundpoint))) - (if (save-excursion - (skip-chars-forward "\t \n") - (looking-at YaTeX::ref-labeling-regexp)) - (setq e0 (match-end 0)))) - (t - (skip-chars-forward " \t") - (setq label (buffer-substring - (match-beginning 0) - (if (re-search-forward - itemsep - nil t) - (progn - (goto-char (match-beginning 0)) - (skip-chars-backward " \t") - (1- (point))) - (point-end-of-line)))) - (funcall output label match-point) - (if (save-excursion - (skip-chars-forward "\t \n") - (looking-at YaTeX::ref-labeling-regexp)) - (setq e0 (match-end 0))))) - ) ;;put label buffer - ;; - ;; if user defined label found - (t - ;; memorize line number and label into property - (goto-char (match-beginning 0)) - (let ((list YaTeX::ref-labeling-regexp-alist) - (cache (symbol-plist 'YaTeX::ref-labeling-regexp))) - (while list - (if (looking-at (car (car list))) - (progn - (setq label (YaTeX-match-string 0)) - (put 'YaTeX::ref-labeling-regexp lnum - (YaTeX-match-string (cdr (car list)))) - (funcall output label 0) ;;0 is dummy, never used - (setq list nil))) - (setq list (cdr list)))) - )) - (goto-char e0)) + + (YaTeX::ref-1) + + (princ YaTeX-label-menu-other) (princ YaTeX-label-menu-repeat) (princ YaTeX-label-menu-any)