(exit-minibuffer))))
(defun calcAlg-blink-matching-open ()
- (let ((oldpos (point))
- (blinkpos nil))
+ (let ((rightpt (point))
+ (leftpt nil)
+ (rightchar (preceding-char))
+ leftchar
+ rightsyntax
+ leftsyntax)
(save-excursion
(condition-case ()
- (setq blinkpos (scan-sexps oldpos -1))
- (error nil)))
- (if (and blinkpos
- (> oldpos (1+ (point-min)))
- (or (and (= (char-after (1- oldpos)) ?\))
- (= (char-after blinkpos) ?\[))
- (and (= (char-after (1- oldpos)) ?\])
- (= (char-after blinkpos) ?\()))
- (save-excursion
- (goto-char blinkpos)
- (looking-at ".+\\(\\.\\.\\|\\\\dots\\|\\\\ldots\\)")))
- (let ((saved (aref (syntax-table) (char-after blinkpos))))
- (unwind-protect
- (progn
- (aset (syntax-table) (char-after blinkpos)
- (+ (logand saved 255)
- (lsh (char-after (1- oldpos)) 8)))
- (blink-matching-open))
- (aset (syntax-table) (char-after blinkpos) saved)))
+ (setq leftpt (scan-sexps rightpt -1)
+ leftchar (char-after leftpt))
+ (error nil)))
+ (if (and leftpt
+ (or (and (= rightchar ?\))
+ (= leftchar ?\[))
+ (and (= rightchar ?\])
+ (= leftchar ?\()))
+ (save-excursion
+ (goto-char leftpt)
+ (looking-at ".+\\(\\.\\.\\|\\\\dots\\|\\\\ldots\\)")))
+ (let ((leftsaved (aref (syntax-table) leftchar))
+ (rightsaved (aref (syntax-table) rightchar)))
+ (unwind-protect
+ (progn
+ (cond ((= leftchar ?\[)
+ (aset (syntax-table) leftchar (cons 4 ?\)))
+ (aset (syntax-table) rightchar (cons 5 ?\[)))
+ (t
+ (aset (syntax-table) leftchar (cons 4 ?\]))
+ (aset (syntax-table) rightchar (cons 5 ?\())))
+ (blink-matching-open))
+ (aset (syntax-table) leftchar leftsaved)
+ (aset (syntax-table) rightchar rightsaved)))
(blink-matching-open))))
-
(defun calc-alg-digit-entry ()
(calc-alg-entry
(cond ((eq last-command-char ?e)
math-exp-pos)
(or (eq math-exp-pos 0)
(and (memq calc-language '(nil flat big unform
- tex eqn))
+ tex latex eqn))
(eq (string-match "[^])}\"a-zA-Z0-9'$]_"
math-exp-str (1- math-exp-pos))
(1- math-exp-pos))))))
math-exp-pos (match-end 0)
math-expr-data (math-restore-dashes
(math-match-substring math-exp-str 1)))
- (let ((code (assoc math-expr-data math-tex-ignore-words)))
+ (let ((code (assoc math-expr-data math-latex-ignore-words)))
+ (cond ((null code))
+ ((null (cdr code))
+ (math-read-token))
+ ((eq (nth 1 code) 'punc)
+ (setq math-exp-token 'punc
+ math-expr-data (nth 2 code)))
+ ((and (eq (nth 1 code) 'mat)
+ (string-match " *{" math-exp-str math-exp-pos))
+ (setq math-exp-pos (match-end 0)
+ math-exp-token 'punc
+ math-expr-data "[")
+ (let ((right (string-match "}" math-exp-str math-exp-pos)))
+ (and right
+ (setq math-exp-str (copy-sequence math-exp-str))
+ (aset math-exp-str right ?\])))))))
+ ((and (= ch ?\\) (eq calc-language 'latex)
+ (< math-exp-pos (1- (length math-exp-str))))
+ (or (string-match "\\\\hbox *{\\([a-zA-Z0-9]+\\)}"
+ math-exp-str math-exp-pos)
+ (string-match "\\\\text *{\\([a-zA-Z0-9]+\\)}"
+ math-exp-str math-exp-pos)
+ (string-match "\\(\\\\\\([a-zA-Z]+\\|[^a-zA-Z]\\)\\)"
+ math-exp-str math-exp-pos))
+ (setq math-exp-token 'symbol
+ math-exp-pos (match-end 0)
+ math-expr-data (math-restore-dashes
+ (math-match-substring math-exp-str 1)))
+ (let ((code (assoc math-expr-data math-tex-ignore-words))
+ envname)
(cond ((null code))
((null (cdr code))
(math-read-token))
((eq (nth 1 code) 'punc)
(setq math-exp-token 'punc
math-expr-data (nth 2 code)))
- ((and (eq (nth 1 code) 'mat)
- (string-match " *{" math-exp-str math-exp-pos))
+ ((and (eq (nth 1 code) 'begenv)
+ (string-match " *{\\([^}]*\\)}" math-exp-str math-exp-pos))
+ (setq math-exp-pos (match-end 0)
+ envname (match-string 1 math-exp-str)
+ math-exp-token 'punc
+ math-expr-data "[")
+ (cond ((or (string= envname "matrix")
+ (string= envname "bmatrix")
+ (string= envname "smallmatrix")
+ (string= envname "pmatrix"))
+ (if (string-match (concat "\\\\end{" envname "}")
+ math-exp-str math-exp-pos)
+ (setq math-exp-str
+ (replace-match "]" t t math-exp-str))
+ (error "%s" (concat "No closing \\end{" envname "}"))))))
+ ((and (eq (nth 1 code) 'mat)
+ (string-match " *{" math-exp-str math-exp-pos))
(setq math-exp-pos (match-end 0)
math-exp-token 'punc
math-expr-data "[")
(setq math-exp-pos (match-end 0))
(math-read-token))
(t
- (if (and (eq ch ?\{) (memq calc-language '(tex eqn)))
+ (if (and (eq ch ?\{) (memq calc-language '(tex latex eqn)))
(setq ch ?\())
- (if (and (eq ch ?\}) (memq calc-language '(tex eqn)))
+ (if (and (eq ch ?\}) (memq calc-language '(tex latex eqn)))
(setq ch ?\)))
- (if (and (eq ch ?\&) (eq calc-language 'tex))
+ (if (and (eq ch ?\&) (memq calc-language '(tex latex)))
(setq ch ?\,))
(setq math-exp-token 'punc
math-expr-data (char-to-string ch)