Commit 0da20854 authored by Stefan Monnier's avatar Stefan Monnier

* lisp/calc/calc-aent.el (calcAlg-blink-matching-check): New fun, to replace

calcAlg-blink-matching-open.
(calc-alg-ent-map, calc-alg-ent-esc-map): Initialize in the declaration.
(calc-do-alg-entry): Only touch the part of the keymap that varies.
Use the new blink-matching-check-function.
parent a49e651e
2010-09-03 Stefan Monnier <monnier@iro.umontreal.ca>
* calc/calc-aent.el (calcAlg-blink-matching-check): New fun, to replace
calcAlg-blink-matching-open.
(calc-alg-ent-map, calc-alg-ent-esc-map): Initialize in the declaration.
(calc-do-alg-entry): Only touch the part of the keymap that varies.
Use the new blink-matching-check-function.
Provide blink-matching support to SMIE.
* emacs-lisp/smie.el (smie-bnf-closer-alist): New function.
(smie-blink-matching-triggers, smie-blink-matching-inners): New vars.
......
......@@ -315,10 +315,24 @@ The value t means abort and give an error message.")
calc-dollar-used 0)))
(calc-handle-whys))))
(defvar calc-alg-ent-map nil
(defvar calc-alg-ent-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map minibuffer-local-map)
(define-key map "'" 'calcAlg-previous)
(define-key map "`" 'calcAlg-edit)
(define-key map "\C-m" 'calcAlg-enter)
(define-key map "\C-j" 'calcAlg-enter)
map)
"The keymap used for algebraic entry.")
(defvar calc-alg-ent-esc-map nil
(defvar calc-alg-ent-esc-map
(let ((map (make-keymap))
(i 33))
(set-keymap-parent map esc-map)
(while (< i 127)
(define-key map (vector i) 'calcAlg-escape)
(setq i (1+ i)))
map)
"The keymap used for escapes in algebraic entry.")
(defvar calc-alg-exp)
......@@ -326,19 +340,8 @@ The value t means abort and give an error message.")
;;;###autoload
(defun calc-do-alg-entry (&optional initial prompt no-normalize history)
(let* ((calc-buffer (current-buffer))
(blink-paren-function 'calcAlg-blink-matching-open)
(blink-matching-check-function 'calcAlg-blink-matching-check)
(calc-alg-exp 'error))
(unless calc-alg-ent-map
(setq calc-alg-ent-map (copy-keymap minibuffer-local-map))
(define-key calc-alg-ent-map "'" 'calcAlg-previous)
(define-key calc-alg-ent-map "`" 'calcAlg-edit)
(define-key calc-alg-ent-map "\C-m" 'calcAlg-enter)
(define-key calc-alg-ent-map "\C-j" 'calcAlg-enter)
(let ((i 33))
(setq calc-alg-ent-esc-map (copy-keymap esc-map))
(while (< i 127)
(aset (nth 1 calc-alg-ent-esc-map) i 'calcAlg-escape)
(setq i (1+ i)))))
(define-key calc-alg-ent-map "\e" nil)
(if (eq calc-algebraic-mode 'total)
(define-key calc-alg-ent-map "\e" calc-alg-ent-esc-map)
......@@ -430,18 +433,9 @@ The value t means abort and give an error message.")
exp))
(exit-minibuffer))))
(defun calcAlg-blink-matching-open ()
(let ((rightpt (point))
(leftpt nil)
(rightchar (preceding-char))
leftchar
rightsyntax
leftsyntax)
(save-excursion
(condition-case ()
(setq leftpt (scan-sexps rightpt -1)
leftchar (char-after leftpt))
(error nil)))
(defun calcAlg-blink-matching-check (leftpt rightpt)
(let ((rightchar (char-before rightpt))
(leftchar (if leftpt (char-after leftpt))))
(if (and leftpt
(or (and (= rightchar ?\))
(= leftchar ?\[))
......@@ -450,20 +444,9 @@ The value t means abort and give an error message.")
(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))))
;; [2..5) perfectly valid!
nil
(blink-matching-check-mismatch leftpt rightpt))))
;;;###autoload
(defun calc-alg-digit-entry ()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment