Mercurial > hgrepos > hgweb.cgi > yatex
comparison yatexmth.el @ 77:1b172d26b55e
Fix auto-fill movement on Emacs21.
Fix YaTeX:ref.
Support jump/change on AMS-LaTeX's parentheses.
author | yuuji |
---|---|
date | Thu, 01 May 2003 13:38:27 +0000 |
parents | 0aaebd07dad0 |
children | 9b4354af748c |
comparison
equal
deleted
inserted
replaced
76:c16a10460ce5 | 77:1b172d26b55e |
---|---|
1 ;;; -*- Emacs-Lisp -*- | 1 ;;; -*- Emacs-Lisp -*- |
2 ;;; YaTeX math-mode-specific functions. | 2 ;;; YaTeX math-mode-specific functions. |
3 ;;; yatexmth.el | 3 ;;; yatexmth.el |
4 ;;; (c)1993-2000 by HIROSE Yuuji [yuuji@yatex.org] | 4 ;;; (c)1993-2003 by HIROSE Yuuji [yuuji@yatex.org] |
5 ;;; Last modified Tue Dec 19 11:03:51 2000 on buell | 5 ;;; Last modified Sun Mar 30 19:56:00 2003 on firestorm |
6 ;;; $Id$ | 6 ;;; $Id$ |
7 | 7 |
8 ;;; [Customization guide] | 8 ;;; [Customization guide] |
9 ;;; | 9 ;;; |
10 ;;; By default, you can use two completion groups in YaTeX math | 10 ;;; By default, you can use two completion groups in YaTeX math |
464 ) | 464 ) |
465 | 465 |
466 (defun YaTeX-math-get-sign (list) | 466 (defun YaTeX-math-get-sign (list) |
467 (YaTeX-math-gets (car (cdr-safe (cdr-safe list)))) | 467 (YaTeX-math-gets (car (cdr-safe (cdr-safe list)))) |
468 ) | 468 ) |
469 (defvar YaTeX-math-section-type-regexp | |
470 "eqn\\\\\\sw+\\b" | |
471 "*Regexp of section-type math-mode macro") | |
472 | |
469 (defun YaTeX-in-math-mode-p () | 473 (defun YaTeX-in-math-mode-p () |
470 "If current position is supposed to be in LaTeX-math-mode, return t." | 474 "If current position is supposed to be in LaTeX-math-mode, return t." |
471 (or (YaTeX-quick-in-environment-p | 475 (or (YaTeX-quick-in-environment-p |
472 (append | 476 (append |
473 '("math" "eqnarray" "equation" "eqnarray*" "displaymath");LaTeX | 477 '("math" "eqnarray" "equation" "eqnarray*" "displaymath");LaTeX |
475 ;; And math modes of AMS-LaTeX | 479 ;; And math modes of AMS-LaTeX |
476 '("align" "align*" "split" "multline" "multline*" "gather" | 480 '("align" "align*" "split" "multline" "multline*" "gather" |
477 "gather*" "aligned*" "gathered" "gathered*" "alignat" | 481 "gather*" "aligned*" "gathered" "gathered*" "alignat" |
478 "equation*" "cases" | 482 "equation*" "cases" |
479 "alignat*" "xalignat" "xalignat*" "xxalignat" "xxalignat*")))) | 483 "alignat*" "xalignat" "xalignat*" "xxalignat" "xxalignat*")))) |
480 (let*((p (point)) (nest 0) me0 | 484 (let*((p (point)) (nest 0) me0 r |
481 (delim (concat YaTeX-sectioning-regexp "\\|^$\\|^\C-l")) | 485 (delim (concat YaTeX-sectioning-regexp "\\|^$\\|^\C-l")) |
482 (boundary | 486 (boundary |
483 (save-excursion | 487 (save-excursion |
484 (if (looking-at delim) | 488 (if (looking-at delim) |
485 (goto-char (max (point-min) (1- (point))))) | 489 (goto-char (max (point-min) (1- (point))))) |
500 (= (char-after (1- me0)) ?\])) | 504 (= (char-after (1- me0)) ?\])) |
501 (setq nest (1+ nest)) | 505 (setq nest (1+ nest)) |
502 (if (= (preceding-char) ?\\ ) nil;;\\[5pt] | 506 (if (= (preceding-char) ?\\ ) nil;;\\[5pt] |
503 (setq nest (1- nest)))))) | 507 (setq nest (1- nest)))))) |
504 (if (< nest 0) (throw 'open t)))) | 508 (if (< nest 0) (throw 'open t)))) |
509 t) | |
510 ((and (setq r (YaTeX-on-section-command-p | |
511 YaTeX-math-section-type-regexp)) | |
512 (numberp r) | |
513 (> r 0)) | |
505 t) | 514 t) |
506 (t (catch 'dollar | 515 (t (catch 'dollar |
507 (while ;(search-backward "$" boundary t);little bit fast. | 516 (while ;(search-backward "$" boundary t);little bit fast. |
508 (YaTeX-re-search-active-backward ;;;;;; Too slow??? | 517 (YaTeX-re-search-active-backward ;;;;;; Too slow??? |
509 "\\$" (concat "[^\\\\]" YaTeX-comment-prefix) boundary t) | 518 "\\$" (concat "[^\\\\]" YaTeX-comment-prefix) boundary t) |
822 (setq flag nil))) | 831 (setq flag nil))) |
823 (setq list (cdr list))))) | 832 (setq list (cdr list))))) |
824 (if (<= move (length (match-string 0))) | 833 (if (<= move (length (match-string 0))) |
825 (match-string 0))))))) | 834 (match-string 0))))))) |
826 | 835 |
827 (defun YaTeX-goto-open-paren () | 836 (defun YaTeX-goto-open-paren (&optional jumpto-co) |
828 "Jump to the exact position of open parenthesis" | 837 "Jump to the exact position of open parenthesis. |
838 If optional argument JUMPTO-CO is non-nil, goto corresponding parentheses." | |
829 (interactive) | 839 (interactive) |
830 (let ((paren) | 840 (let ((paren) |
831 (backslash-syntax (char-to-string (char-syntax ?\\)))) | 841 (backslash-syntax (char-to-string (char-syntax ?\\)))) |
832 (if (setq paren (YaTeX-on-parenthesis-p)) | 842 (if (setq paren (YaTeX-on-parenthesis-p)) |
833 (if (string-match "(\\|{\\|\\[" paren (1- (length paren))) | 843 (if (string-match "(\\|{\\|\\[" paren (1- (length paren))) |
834 (progn | 844 (progn |
835 (re-search-forward "(\\|{\\|\\[" (+ (point) (length paren)) t) | 845 (re-search-forward "(\\|{\\|\\[" (+ (point) (length paren)) t) |
836 (backward-char)) | 846 (backward-char) |
847 (if jumpto-co | |
848 (unwind-protect | |
849 (progn | |
850 (modify-syntax-entry ?\\ " ") | |
851 (forward-list) | |
852 (backward-char)) | |
853 (modify-syntax-entry ?\\ backslash-syntax))) | |
854 (point)) | |
837 (re-search-forward ")\\|}\\|\\]" (+ (point) (length paren)) t) | 855 (re-search-forward ")\\|}\\|\\]" (+ (point) (length paren)) t) |
838 (unwind-protect | 856 (unwind-protect |
839 (progn | 857 (progn |
840 (modify-syntax-entry ?\\ " ") | 858 (modify-syntax-entry ?\\ " ") |
841 (backward-list)) | 859 (backward-list) |
860 (point)) | |
842 (modify-syntax-entry ?\\ backslash-syntax)))))) | 861 (modify-syntax-entry ?\\ backslash-syntax)))))) |
862 | |
863 ;;;###autoload | |
864 (defun YaTeX-goto-corresponding-paren () | |
865 "Go to corresponding mathematical parentheses." | |
866 (if (YaTeX-on-parenthesis-p) | |
867 (YaTeX-goto-open-paren t) | |
868 nil)) | |
843 | 869 |
844 (defun YaTeX-change-parentheses () | 870 (defun YaTeX-change-parentheses () |
845 "Change the size of parentheses, braces, and brackets of AMS-LaTeX." | 871 "Change the size of parentheses, braces, and brackets of AMS-LaTeX." |
846 (interactive) | 872 (interactive) |
847 (if (not (and YaTeX-use-AMS-LaTeX (YaTeX-on-parenthesis-p))) | 873 (if (not (and YaTeX-use-AMS-LaTeX (YaTeX-on-parenthesis-p))) |
853 (length mod))) ;; length of modifier | 879 (length mod))) ;; length of modifier |
854 (paren-length (length paren)) ;; length of paren | 880 (paren-length (length paren)) ;; length of paren |
855 (length (+ mod-length paren-length)) ;; length of whole string | 881 (length (+ mod-length paren-length)) ;; length of whole string |
856 (big-p t) ;; flag whether new modifier is "[Bb]ig+" or not. | 882 (big-p t) ;; flag whether new modifier is "[Bb]ig+" or not. |
857 size ;; left, big, Big etc. | 883 size ;; left, big, Big etc. |
884 type ;; parentheses type | |
858 lr ;; "l" or "r". | 885 lr ;; "l" or "r". |
859 char newsize newsize-length | 886 char newsize newsize-length |
860 (backslash-syntax (char-to-string (char-syntax ?\\))) | 887 (backslash-syntax (char-to-string (char-syntax ?\\))) |
861 (case-fold-search)) | 888 (case-fold-search)) |
862 ;; decide lr and size from mod and paren. | 889 ;; decide lr and size from mod and paren. |
874 (t | 901 (t |
875 (setq size nil lr nil))) | 902 (setq size nil lr nil))) |
876 (while (not newsize) | 903 (while (not newsize) |
877 (message (format (concat "Change from %s: " | 904 (message (format (concat "Change from %s: " |
878 "l(big) L(Big) h(bigg) H(Bigg) " | 905 "l(big) L(Big) h(bigg) H(Bigg) " |
879 "r(left-right) n(NONE) ") size)) | 906 "r(left-right) n(NONE) ( { [") size)) |
880 (setq char (read-char) | 907 (setq char (read-char) |
881 newsize (cond ((char-equal char ?l) "\\big") | 908 newsize (cond ((char-equal char ?l) "\\big") |
882 ((char-equal char ?L) "\\Big") | 909 ((char-equal char ?L) "\\Big") |
883 ((char-equal char ?h) "\\bigg") | 910 ((char-equal char ?h) "\\bigg") |
884 ((char-equal char ?H) "\\Bigg") | 911 ((char-equal char ?H) "\\Bigg") |
885 ((char-equal char ?r) | 912 ((char-equal char ?r) |
886 (setq big-p nil) "\\left") | 913 (setq big-p nil) "\\left") |
914 ((memq char '(?\( ?\))) | |
915 (setq big-p nil type '("(" . ")")) "") | |
916 ((memq char '(?\{ ?\})) | |
917 (setq big-p nil type '("\\{" . "\\}")) "") | |
918 ((memq char '(?\[ ?\])) | |
919 (setq big-p nil type '("[" . "]")) "") | |
887 ((char-equal char ?n) | 920 ((char-equal char ?n) |
888 (setq big-p nil) "") | 921 (setq big-p nil) "") |
889 (t nil)) | 922 (t nil)) |
890 newsize-length (length newsize))) | 923 newsize-length (length newsize))) |
891 (YaTeX-goto-open-paren) | 924 (YaTeX-goto-open-paren) |
892 (forward-char) | 925 (forward-char) |
893 (delete-region (- (point) length) (- (point) paren-length)) | 926 (cond |
894 (backward-char paren-length) | 927 (type |
928 (delete-region (point) (- (point) paren-length)) | |
929 (save-excursion (insert (car type)))) | |
930 (t | |
931 (delete-region (- (point) length) (- (point) paren-length)) | |
932 (backward-char paren-length))) | |
895 (insert-string newsize) | 933 (insert-string newsize) |
896 (if big-p (insert ?l)) | 934 (if big-p (insert ?l)) |
897 (forward-char (1- paren-length)) | |
898 (unwind-protect | 935 (unwind-protect |
899 (progn | 936 (progn |
900 (modify-syntax-entry ?\\ " ") | 937 (modify-syntax-entry ?\\ " ") |
901 (forward-list) | 938 (forward-list) |
902 (if (string= size "left-right") (setq length (1+ length))) | 939 (if (string= size "left-right") (setq length (1+ length))) |
903 (if (eq char ?r) (setq newsize "\\right")) | 940 (if (eq char ?r) (setq newsize "\\right")) |
904 (delete-region (- (point) length) (- (point) paren-length)) | 941 (cond |
905 (backward-char paren-length) | 942 (type |
906 (insert-string newsize) | 943 (delete-region (point) (- (point) paren-length)) |
907 (if big-p (insert ?r)) | 944 (insert (cdr type))) |
908 (forward-char paren-length) | 945 (t |
946 (delete-region (- (point) length) (- (point) paren-length)) | |
947 (backward-char paren-length) | |
948 (insert-string newsize) | |
949 (if big-p (insert ?r)) | |
950 (forward-char paren-length))) | |
909 (if (string= lr "l") (backward-list))) | 951 (if (string= lr "l") (backward-list))) |
910 (modify-syntax-entry ?\\ backslash-syntax)) | 952 (modify-syntax-entry ?\\ backslash-syntax)) |
911 t))) | 953 t))) |
912 | 954 |
913 (defun YaTeX-insert-amsparens-region (beg end char) | 955 (defun YaTeX-insert-amsparens-region (beg end char) |