From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#10906: 24.0.94; `c-mark-function' does set the mark well Date: Wed, 7 Mar 2012 21:09:29 +0000 Message-ID: <20120307210929.GA2486@acm.acm> References: <20120301212404.GB19099@acm.acm> <20120305184133.GC2824@acm.acm> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1331154704 6935 80.91.229.3 (7 Mar 2012 21:11:44 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 7 Mar 2012 21:11:44 +0000 (UTC) Cc: 10906@debbugs.gnu.org To: Dani Moncayo Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Mar 07 22:11:41 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1S5O96-0000T6-8L for geb-bug-gnu-emacs@m.gmane.org; Wed, 07 Mar 2012 22:11:40 +0100 Original-Received: from localhost ([::1]:60871 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5O95-0001eT-Ii for geb-bug-gnu-emacs@m.gmane.org; Wed, 07 Mar 2012 16:11:39 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:54558) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5O92-0001dH-9S for bug-gnu-emacs@gnu.org; Wed, 07 Mar 2012 16:11:37 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S5O90-0000Lq-Cd for bug-gnu-emacs@gnu.org; Wed, 07 Mar 2012 16:11:35 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:59395) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5O8x-0000Kr-D9; Wed, 07 Mar 2012 16:11:31 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1S5O9R-0003BV-SJ; Wed, 07 Mar 2012 16:12:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Wed, 07 Mar 2012 21:12:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 10906 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 10906-submit@debbugs.gnu.org id=B10906.133115469512203 (code B ref 10906); Wed, 07 Mar 2012 21:12:01 +0000 Original-Received: (at 10906) by debbugs.gnu.org; 7 Mar 2012 21:11:35 +0000 Original-Received: from localhost ([127.0.0.1]:37994 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1S5O90-0003Ac-Om for submit@debbugs.gnu.org; Wed, 07 Mar 2012 16:11:35 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:18269 helo=mail.muc.de) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1S5O8o-0003AF-18 for 10906@debbugs.gnu.org; Wed, 07 Mar 2012 16:11:23 -0500 Original-Received: (qmail 8030 invoked by uid 3782); 7 Mar 2012 21:10:19 -0000 Original-Received: from acm.muc.de (pD951AE67.dip.t-dialin.net [217.81.174.103]) by colin.muc.de (tmda-ofmipd) with ESMTP; Wed, 07 Mar 2012 22:10:17 +0100 Original-Received: (qmail 4061 invoked by uid 1000); 7 Mar 2012 21:09:29 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:57557 Archived-At: Hello, Dani. On Mon, Mar 05, 2012 at 11:36:52PM +0100, Dani Moncayo wrote: > On Mon, Mar 5, 2012 at 19:41, Alan Mackenzie wrote: > > Here is a patch which should fix these problems.  The logic around > > transient-mark-mode is somewhat complicated, so I would be grateful if > > you would check the patch does the Right Thing.  I haven't amended the > > doc string yet.  Thanks! > Thank you. > I've tried your patch, and it seems to work[*], at least with my usage > pattern, i.e., with `transient-mark-mode' enabled. > [*] Except for one thing: > - If you do `C-M-h' several times in a row until the mark reaches the > end of the file, the point ends up at the end of the region, and the > mark at the beginning (which doesn't seem right). > - If you try the same experiment with `mark-defun', the mark stays at > the end and the point at the start of the region (as expected). Thanks for spotting that. Here's a revised patch. I think it'll work this time. diff -r f6961b0b1c51 cc-cmds.el --- a/cc-cmds.el Fri Mar 02 21:25:40 2012 +0000 +++ b/cc-cmds.el Wed Mar 07 21:06:31 2012 +0000 @@ -1950,7 +1950,12 @@ (defun c-mark-function () "Put mark at end of the current top-level declaration or macro, point at beginning. -If point is not inside any then the closest following one is chosen. +If point is not inside any then the closest following one is +chosen. Each successive call of this command extends the marked +region by one function. + +A mark is left where the command started, unless the region is already active +\(in Transient Mark mode). As opposed to \\[c-beginning-of-defun] and \\[c-end-of-defun], this function does not require the declaration to contain a brace block." @@ -1966,8 +1971,24 @@ (if (not decl-limits) (error "Cannot find any declaration") - (goto-char (car decl-limits)) - (push-mark (cdr decl-limits) nil t)))) + (let* ((extend-region-p + (or (and (eq this-command 'c-mark-function) + (eq last-command 'c-mark-function)))) + (push-mark-p (and (eq this-command 'c-mark-function) + (not extend-region-p) + (not (and transient-mark-mode mark-active))))) + (if push-mark-p (push-mark (point))) + (if extend-region-p + (progn + (exchange-point-and-mark) + (setq decl-limits (c-declaration-limits t)) + (when (not decl-limits) + (exchange-point-and-mark) + (error "Cannot find any declaration")) + (goto-char (cdr decl-limits)) + (exchange-point-and-mark)) + (goto-char (car decl-limits)) + (push-mark (cdr decl-limits) nil t)))))) (defun c-cpp-define-name () "Return the name of the current CPP macro, or NIL if we're not in one." > -- > Dani Moncayo -- Alan Mackenzie (Nuremberg, Germany).