From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Alan Mackenzie <acm@muc.de>
Cc: emacs-devel@gnu.org
Subject: Re: Proposed extension of show-paren-mode: Highlight parens when point is in L or R margin.
Date: Sun, 12 Oct 2014 00:12:12 -0400 [thread overview]
Message-ID: <jwvbnpiorx4.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <20141011134312.GA4148@acm.acm> (Alan Mackenzie's message of "Sat, 11 Oct 2014 13:43:12 +0000")
> So: If point is in the LH margin of the code, highlight the first paren
> on the line and its match, or failing that, the last paren on the line
> with its match.
Related ideas:
- show matching paren when point is right after the open paren or right
before the close paren. (see
http://stackoverflow.com/questions/25648067/emacs-matching-parenthesis-when-cursor-is-on-closing-parenthesis
for a 5-liner which does that).
- show matching paren, when there's only whitespace between point and
the open/close paren.
This second idea is a superset of the one you suggest. I personally
don't use show-paren-mode because I find it distracting, so maybe
a superset would be too distracting.
> Then again, why not do the same if point is in a line comment?
Sorry, I don't know what "in a line comment" means.
As for your patch, I'd rather see the new code moved to a new function.
See more detailed comments below.
Stefan
> + (defcustom show-paren-when-point-in-margin nil
Please don't call it "margin".
> ! (cond
> ! ;; Point is at a paren.
> ! ((eq (syntax-class (syntax-after (1- (point)))) 5)
> ! (setq dir -1))
> ! ((eq (syntax-class (syntax-after (point))) 4)
> ! (setq dir 1))
> ! ;; Point is in the LH margin.
> ! ((and show-paren-when-point-in-margin
> ! (< (point) ind-pos))
> ! (cond
> ! ((eq (syntax-class (syntax-after ind-pos)) 4)
> ! (setq dir 1
> ! oldpos ind-pos))
> ! ((eq (syntax-class (syntax-after ind-pos)) 5)
> ! (setq dir -1
> ! oldpos (1+ ind-pos)))
> ! ((eq (syntax-class (syntax-after (1- eol-pos))) 4)
> ! (setq dir 1
> ! oldpos (1- eol-pos)))
> ! ((eq (syntax-class (syntax-after (1- eol-pos))) 5)
> ! (setq dir -1
> ! oldpos eol-pos))))
> ! ;; Point is in a comment or whitespace to the right of the line.
> ! ((and show-paren-when-point-in-margin
> ! (>= (point) eol-pos))
> ! (cond
> ! ((eq (syntax-class (syntax-after (1- eol-pos))) 4)
> ! (setq dir 1
> ! oldpos (1- eol-pos)))
> ! ((eq (syntax-class (syntax-after (1- eol-pos))) 5)
> ! (setq dir -1
> ! oldpos eol-pos)))))
It's not at all clear to me why there has to be so many different cases
(IOW we'd need a comment that explains why we need such complexity).
> ! (when dir
> ! (setq unescaped
> ! (= (if (= dir -1) 1 0)
> ! (logand 1 (- oldpos
> ! (save-excursion
> ! (goto-char oldpos)
> ! (if (= dir -1) (backward-char))
> ! (skip-syntax-backward "/\\")
> ! (point)))))))
This is a code duplication. Please move it to a separate helper function.
Stefan
next prev parent reply other threads:[~2014-10-12 4:12 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-11 13:43 Proposed extension of show-paren-mode: Highlight parens when point is in L or R margin Alan Mackenzie
2014-10-11 14:21 ` Eli Zaretskii
2014-10-12 8:39 ` Alan Mackenzie
2014-10-12 8:55 ` David Kastrup
2014-10-12 9:25 ` Alan Mackenzie
2014-10-12 9:01 ` Eli Zaretskii
2014-10-12 10:18 ` Alan Mackenzie
2014-10-12 4:12 ` Stefan Monnier [this message]
2014-10-12 10:04 ` Alan Mackenzie
2014-10-14 17:49 ` Stefan Monnier
2014-10-14 18:32 ` John Yates
2014-10-15 9:12 ` Alan Mackenzie
2014-10-15 22:38 ` Andy Moreton
2014-10-16 2:43 ` Stefan Monnier
2014-10-16 9:53 ` Alan Mackenzie
2014-10-16 12:59 ` Stefan Monnier
2014-10-16 13:31 ` Alan Mackenzie
2014-10-16 14:37 ` Stefan Monnier
2014-10-16 15:46 ` Alan Mackenzie
2014-10-16 17:40 ` Stefan Monnier
2014-10-16 21:26 ` Alan Mackenzie
2014-10-17 0:14 ` Stefan Monnier
2014-10-14 21:50 ` João Távora
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvbnpiorx4.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=acm@muc.de \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.