From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel 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 Message-ID: References: <20141011134312.GA4148@acm.acm> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1413087169 10105 80.91.229.3 (12 Oct 2014 04:12:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 12 Oct 2014 04:12:49 +0000 (UTC) Cc: emacs-devel@gnu.org To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Oct 12 06:12:43 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XdAWQ-0000lX-Ln for ged-emacs-devel@m.gmane.org; Sun, 12 Oct 2014 06:12:42 +0200 Original-Received: from localhost ([::1]:55996 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XdAWQ-0008Jm-4l for ged-emacs-devel@m.gmane.org; Sun, 12 Oct 2014 00:12:42 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44525) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XdAW8-0008Jg-Ik for emacs-devel@gnu.org; Sun, 12 Oct 2014 00:12:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XdAW2-000291-Az for emacs-devel@gnu.org; Sun, 12 Oct 2014 00:12:24 -0400 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:40061) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XdAW2-00028x-5P for emacs-devel@gnu.org; Sun, 12 Oct 2014 00:12:18 -0400 Original-Received: from fmsmemgm.homelinux.net (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id s9C4CD1t012523; Sun, 12 Oct 2014 00:12:15 -0400 Original-Received: by fmsmemgm.homelinux.net (Postfix, from userid 20848) id 92310AE0BA; Sun, 12 Oct 2014 00:12:12 -0400 (EDT) In-Reply-To: <20141011134312.GA4148@acm.acm> (Alan Mackenzie's message of "Sat, 11 Oct 2014 13:43:12 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux) X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV5091=0 X-NAI-Spam-Version: 2.3.0.9378 : core <5091> : inlines <1393> : streams <1314513> : uri <1824002> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 132.204.246.20 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:175272 Archived-At: > 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