comparison lisp/simple.el @ 5773:94a6b8fbd56e

Use a face, show more context around open parenthesis, #'blink-matching-open lisp/ChangeLog addition: 2013-12-17 Aidan Kehoe <kehoea@parhasard.net> * simple.el (blink-matching-open): When showing the opening parenthesis in the minibiffer, use the isearch face for it, in case there are multiple parentheses in the text shown. When writing moderately involved macros, it's often not enough just to show the backquote context before the parenthesis (e.g. @,.`). Skip over that when searching for useful context in the same way we skip over space and tab. * simple.el (message): * simple.el (lmessage): If there are no ARGS, don't call #'format. This allows extent information to be passed through to the minibuffer. It's probably better still to update #'format to preserve extent info.
author Aidan Kehoe <kehoea@parhasard.net>
date Tue, 17 Dec 2013 20:49:52 +0200
parents 0eb4e96fd261
children b79e1e02bf01
comparison
equal deleted inserted replaced
5772:cd4f5f1f1f4c 5773:94a6b8fbd56e
3302 (blinkpos) 3302 (blinkpos)
3303 (mismatch)) 3303 (mismatch))
3304 (save-excursion 3304 (save-excursion
3305 (save-restriction 3305 (save-restriction
3306 (if blink-matching-paren-distance 3306 (if blink-matching-paren-distance
3307 (narrow-to-region (max (point-min) 3307 (narrow-to-region
3308 (- (point) blink-matching-paren-distance)) 3308 (max (point-min)
3309 oldpos)) 3309 (- (point) blink-matching-paren-distance))
3310 oldpos))
3310 (condition-case () 3311 (condition-case ()
3311 (let ((parse-sexp-ignore-comments 3312 (let ((parse-sexp-ignore-comments
3312 (and parse-sexp-ignore-comments 3313 (and parse-sexp-ignore-comments
3313 (not blink-matching-paren-dont-ignore-comments)))) 3314 (not blink-matching-paren-dont-ignore-comments))))
3314 (setq blinkpos (scan-sexps oldpos -1))) 3315 (setq blinkpos (scan-sexps oldpos -1)))
3320 (or (null (matching-paren (char-after blinkpos))) 3321 (or (null (matching-paren (char-after blinkpos)))
3321 (/= (char-after (1- oldpos)) 3322 (/= (char-after (1- oldpos))
3322 (matching-paren (char-after blinkpos)))))) 3323 (matching-paren (char-after blinkpos))))))
3323 (if mismatch (setq blinkpos nil)) 3324 (if mismatch (setq blinkpos nil))
3324 (if blinkpos 3325 (if blinkpos
3325 (progn 3326 (labels
3326 (goto-char blinkpos) 3327 ((buffer-substring-highlight-blinkpos (start end)
3327 (if (pos-visible-in-window-p) 3328 ;; Sometimes there are sufficiently many
3328 (and blink-matching-paren-on-screen 3329 ;; parentheses on a line that it's *very*
3329 (progn 3330 ;; useful to see exactly which is the match.
3330 (auto-show-make-point-visible) 3331 (let* ((string (buffer-substring start end))
3331 (sit-for blink-matching-delay))) 3332 (extent (make-extent (- blinkpos start)
3332 (goto-char blinkpos) 3333 (1+ (- blinkpos start))
3333 (lmessage 'command "Matches %s" 3334 string)))
3334 ;; Show what precedes the open in its line, if anything. 3335 (set-extent-face extent 'isearch)
3335 (if (save-excursion 3336 (set-extent-property extent 'duplicable t)
3336 (skip-chars-backward " \t") 3337 string))
3337 (not (bolp))) 3338 (before-backquote-context ()
3338 (buffer-substring (progn (beginning-of-line) (point)) 3339 ;; Just showing the backquote context is often not
3339 (1+ blinkpos)) 3340 ;; informative enough, if you're writing vaguely
3340 ;; Show what follows the open in its line, if anything. 3341 ;; complex macros. Move past it.
3341 (if (save-excursion 3342 (skip-chars-backward "`,@.")))
3342 (forward-char 1) 3343 (declare (inline before-backquote-context))
3343 (skip-chars-forward " \t") 3344 (goto-char blinkpos)
3344 (not (eolp))) 3345 (if (pos-visible-in-window-p)
3345 (buffer-substring blinkpos 3346 (and blink-matching-paren-on-screen
3346 (progn (end-of-line) (point))) 3347 (progn
3347 ;; Otherwise show the previous nonblank line, 3348 (auto-show-make-point-visible)
3348 ;; if there is one. 3349 (sit-for blink-matching-delay)))
3349 (if (save-excursion 3350 (goto-char blinkpos)
3350 (skip-chars-backward "\n \t") 3351 (lmessage
3351 (not (bobp))) 3352 'command
3352 (concat 3353 (concat
3353 (buffer-substring (progn 3354 "Matches "
3354 (skip-chars-backward "\n \t") 3355 ;; Show what precedes the open in its line, if
3355 (beginning-of-line) 3356 ;; anything.
3356 (point)) 3357 (if (save-excursion
3357 (progn (end-of-line) 3358 (before-backquote-context)
3358 (skip-chars-backward " \t") 3359 (skip-chars-backward " \t")
3359 (point))) 3360 (not (bolp)))
3360 ;; Replace the newline and other whitespace with `...'. 3361 (buffer-substring-highlight-blinkpos
3361 "..." 3362 (progn (beginning-of-line) (point))
3362 (buffer-substring blinkpos (1+ blinkpos))) 3363 (1+ blinkpos))
3363 ;; There is nothing to show except the char itself. 3364 ;; Show what follows the open in its line, if
3364 (buffer-substring blinkpos (1+ blinkpos)))))))) 3365 ;; anything.
3366 (if (save-excursion
3367 (forward-char 1)
3368 (skip-chars-forward " \t")
3369 (not (eolp)))
3370 (buffer-substring-highlight-blinkpos
3371 (progn (before-backquote-context) (point))
3372 (progn (end-of-line (point))))
3373 ;; Otherwise show the previous nonblank line,
3374 ;; if there is one.
3375 (if (save-excursion
3376 (skip-chars-backward "\n \t")
3377 (not (bobp)))
3378 (concat
3379 (buffer-substring
3380 (progn (skip-chars-backward "\n \t")
3381 (beginning-of-line)
3382 (point))
3383 (progn (end-of-line)
3384 (skip-chars-backward " \t")
3385 (point)))
3386 ;; Replace the newline and other whitespace
3387 ;; with `...'.
3388 "..."
3389 (buffer-substring-highlight-blinkpos
3390 blinkpos (1+ blinkpos)))
3391 ;; There is nothing to show except the char
3392 ;; itself.
3393 (buffer-substring-highlight-blinkpos
3394 blinkpos (1+ blinkpos)))))))))
3365 (cond (mismatch 3395 (cond (mismatch
3366 (display-message 'no-log "Mismatched parentheses")) 3396 (display-message 'no-log "Mismatched parentheses"))
3367 ((not blink-matching-paren-distance) 3397 ((not blink-matching-paren-distance)
3368 (display-message 'no-log "Unmatched parenthesis")))))))) 3398 (display-message 'no-log "Unmatched parenthesis"))))))))
3369 3399
4499 ;; (if (framep default-minibuffer-frame) 4529 ;; (if (framep default-minibuffer-frame)
4500 ;; (make-frame-visible default-minibuffer-frame)) 4530 ;; (make-frame-visible default-minibuffer-frame))
4501 (if (and (null fmt) (null args)) 4531 (if (and (null fmt) (null args))
4502 (prog1 nil 4532 (prog1 nil
4503 (clear-message nil)) 4533 (clear-message nil))
4504 (let ((str (apply 'format fmt args))) 4534 (let ((string (if args (apply 'format fmt args) fmt)))
4505 (display-message 'message str) 4535 (display-message 'message string)
4506 str))) 4536 string)))
4507 4537
4508 (defun lmessage (label fmt &rest args) 4538 (defun lmessage (label fmt &rest args)
4509 "Print a one-line message at the bottom of the frame. 4539 "Print a one-line message at the bottom of the frame.
4510 First argument LABEL is an identifier for this message. The rest of the 4540 First argument LABEL is an identifier for this message. The rest of the
4511 arguments are the same as to `format'. 4541 arguments are the same as to `format'.
4512 4542
4513 See `display-message' for a list of standard labels." 4543 See `display-message' for a list of standard labels."
4514 (if (and (null fmt) (null args)) 4544 (if (and (null fmt) (null args))
4515 (prog1 nil 4545 (prog1 nil
4516 (clear-message label nil)) 4546 (clear-message label nil))
4517 (let ((str (apply 'format fmt args))) 4547 (let ((string (if args (apply 'format fmt args) fmt)))
4518 (display-message label str) 4548 (display-message label string)
4519 str))) 4549 string)))
4520
4521 4550
4522 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 4551 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4523 ;; warning code ;; 4552 ;; warning code ;;
4524 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 4553 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4525 4554