[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: blink-matching-open resizes echo area
From: |
martin rudalics |
Subject: |
Re: blink-matching-open resizes echo area |
Date: |
Tue, 23 Aug 2005 19:19:21 +0200 |
User-agent: |
Mozilla Thunderbird 1.0 (Windows/20041206) |
Does this version work right?
(defun blink-matching-open ()
"Move cursor momentarily to the beginning of the sexp before point."
(interactive)
...
It does, but I would apply some further changes:
(1) Relocate the comment "Don't log messages about paren matching.".
(2) Replace "(/= (char-after (1- oldpos)) matching-paren)" by
"(/= (char-before oldpos) matching-paren)".
(3) Replace
(if (save-excursion
(goto-char blinkpos)
(pos-visible-in-window-p))
by
(if (pos-visible-in-window-p blinkpos)
(4) Replace "(progn (beginning-of-line) (point))" by "(line-beginning-position)"
and "(progn (end-of-line) (point))" by "(line-end-position)".
Moreover, I'd do away with `mismatch' and `matching-paren', not move
around unnecessarily when `blink-matching-paren-on-screen' is nil or a
previous nonblank line can be found, and regroup some of the conditions
a bit - tiny changes only, but I'm afraid this won't convince you ...
(defun blink-matching-open ()
"Move cursor momentarily to the beginning of the sexp before point."
(interactive)
(when (and (> (point) (1+ (point-min)))
blink-matching-paren
;; Verify an even number of quoting characters precede the close.
(= 1 (logand 1 (- (point)
(save-excursion
(forward-char -1)
(skip-syntax-backward "/\\")
(point))))))
(let ((oldpos (point))
blinkpos
message-log-max ; Don't log messages about paren matching.
open-paren-line-string)
(save-excursion
(save-restriction
(if blink-matching-paren-distance
(narrow-to-region (max (point-min)
(- (point) blink-matching-paren-distance))
oldpos))
(condition-case ()
(let ((parse-sexp-ignore-comments
(and parse-sexp-ignore-comments
(not blink-matching-paren-dont-ignore-comments))))
(setq blinkpos (scan-sexps oldpos -1)))
(error nil)))
(cond
((not blinkpos)
;; No matching open found.
(unless blink-matching-paren-distance
(message "Unmatched parenthesis")))
((let ((syntax (syntax-after blinkpos)))
;; Not syntax '$'.
(and (not (eq (syntax-class syntax) 8))
(or (not (consp syntax))
(not (eq (syntax-class syntax) 4))
(null (cdr syntax))
(/= (char-before oldpos) (cdr syntax)))))
;; Mismatching open.
(message "Mismatched parentheses"))
((pos-visible-in-window-p blinkpos)
;; Matching open within window, temporarily move to blinkpos but only
;; if `blink-matching-paren-on-screen' is non-nil.
(when blink-matching-paren-on-screen
(goto-char blinkpos)
(sit-for blink-matching-delay)))
(t
;; Matching open not within window.
(goto-char blinkpos)
(setq open-paren-line-string
(cond
;; Show what precedes the open in its line, if anything.
((save-excursion
(skip-chars-backward " \t")
(not (bolp)))
(buffer-substring (line-beginning-position) (1+ blinkpos)))
;; Show what follows the open in its line, if anything.
((save-excursion
(forward-char 1)
(skip-chars-forward " \t")
(not (eolp)))
(buffer-substring blinkpos (line-end-position)))
;; Show the previous nonblank line, if there is one.
((progn
(skip-chars-backward "\n \t")
(not (bobp)))
(concat
(buffer-substring
(line-beginning-position)
(progn
(end-of-line)
(skip-chars-backward " \t")
(point)))
;; Replace newline(s) and other whitespace with `...'.
"..."
(buffer-substring blinkpos (1+ blinkpos))))
;; There is nothing to show except the char itself.
(t (buffer-substring blinkpos (1+ blinkpos)))))
(message "Matches %s"
(substring-no-properties open-paren-line-string))))))))