unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* blink-matching-open resizes echo area
@ 2005-08-20  8:44 martin rudalics
  2005-08-22  0:06 ` Richard M. Stallman
  0 siblings, 1 reply; 4+ messages in thread
From: martin rudalics @ 2005-08-20  8:44 UTC (permalink / raw)


Suppose all "blink-matching..." variables at their standard settings.
When I now insert a closing paren in the current buffer and (a) the
matching paren is before `window-start' and (b) the `buffer-substring'
to be displayed by `blink-matching-open' contains at least one bold
character, the following happens: Emacs resizes the echo area to show
the string (apparently to accomodate the bold character) and recenters
the current buffer.  The combined effects are distracting.

A workaround is to replace `buffer-string' in `blink-matching-open' by
`buffer-substring-no-properties'.  Binding `max-mini-window-height'
temporarily to 1 is better - Emacs doesn't recenter any more but still
resizes the echo area.  Personally, I'd prefer a solution that would not
resize the echo area at all in this particular case but probably I'm
asking too much.

An aside: When I activate `show-paren-mode' the latter setqs the
variable `blink-matching-paren-on-screen'.  Customizing that variable
now tells me "CHANGED outside Customize; operating on it here may be
unreliable".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: blink-matching-open resizes echo area
  2005-08-20  8:44 blink-matching-open resizes echo area martin rudalics
@ 2005-08-22  0:06 ` Richard M. Stallman
  2005-08-23 17:19   ` martin rudalics
  0 siblings, 1 reply; 4+ messages in thread
From: Richard M. Stallman @ 2005-08-22  0:06 UTC (permalink / raw)
  Cc: emacs-devel

Does this version work right?


(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)
	   (mismatch)
	   message-log-max
	   matching-paren
	   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)))
	(and blinkpos
	     ;; Not syntax '$'.
	     (not (eq (syntax-class (syntax-after blinkpos)) 8))
	     (setq matching-paren
		   (let ((syntax (syntax-after blinkpos)))
		     (and (consp syntax)
			  (eq (syntax-class syntax) 4)
			  (cdr syntax)))
		   mismatch
		   (or (null matching-paren)
		       (/= (char-after (1- oldpos))
			   matching-paren))))
	(if mismatch (setq blinkpos nil))
	(if blinkpos
	    ;; Don't log messages about paren matching.
	    (if (save-excursion
		  (goto-char blinkpos)
		  (pos-visible-in-window-p))
		(progn
		  (goto-char blinkpos)
		  (and blink-matching-paren-on-screen
		       (sit-for blink-matching-delay)))
	      (save-excursion
		(goto-char blinkpos)
		(setq open-paren-line-string
		      ;; Show what precedes the open in its line, if anything.
		      (if (save-excursion
			    (skip-chars-backward " \t")
			    (not (bolp)))
			  (buffer-substring (progn (beginning-of-line) (point))
					    (1+ blinkpos))
			;; Show what follows the open in its line, if anything.
			(if (save-excursion
			      (forward-char 1)
			      (skip-chars-forward " \t")
			      (not (eolp)))
			    (buffer-substring blinkpos
					      (progn (end-of-line) (point)))
			  ;; Otherwise show the previous nonblank line,
			  ;; if there is one.
			  (if (save-excursion
				(skip-chars-backward "\n \t")
				(not (bobp)))
			      (concat
			       (buffer-substring (progn
						   (skip-chars-backward "\n \t")
						   (beginning-of-line)
						   (point))
						 (progn (end-of-line)
							(skip-chars-backward " \t")
							(point)))
			       ;; Replace the newline and other whitespace with `...'.
			       "..."
			       (buffer-substring blinkpos (1+ blinkpos)))
			    ;; There is nothing to show except the char itself.
			    (buffer-substring blinkpos (1+ blinkpos)))))))
	      (message "Matches %s"
		       (substring-no-properties open-paren-line-string)))
	  (cond (mismatch
		 (message "Mismatched parentheses"))
		((not blink-matching-paren-distance)
		 (message "Unmatched parenthesis"))))))))

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: blink-matching-open resizes echo area
  2005-08-22  0:06 ` Richard M. Stallman
@ 2005-08-23 17:19   ` martin rudalics
  2005-08-28 15:12     ` Richard M. Stallman
  0 siblings, 1 reply; 4+ messages in thread
From: martin rudalics @ 2005-08-23 17:19 UTC (permalink / raw)
  Cc: emacs-devel

> 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))))))))

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: blink-matching-open resizes echo area
  2005-08-23 17:19   ` martin rudalics
@ 2005-08-28 15:12     ` Richard M. Stallman
  0 siblings, 0 replies; 4+ messages in thread
From: Richard M. Stallman @ 2005-08-28 15:12 UTC (permalink / raw)
  Cc: emacs-devel

I will use some of these changes.  Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-08-28 15:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-20  8:44 blink-matching-open resizes echo area martin rudalics
2005-08-22  0:06 ` Richard M. Stallman
2005-08-23 17:19   ` martin rudalics
2005-08-28 15:12     ` Richard M. Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).