GNU bug report logs - #10906
24.0.94; `c-mark-function' does set the mark well

Previous Next

Packages: cc-mode, emacs;

Reported by: Dani Moncayo <dmoncayo <at> gmail.com>

Date: Tue, 28 Feb 2012 12:41:01 UTC

Severity: normal

Found in version 24.0.94

Done: Alan Mackenzie <acm <at> muc.de>

Bug is archived. No further changes may be made.

Full log


Message #29 received at 10906 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Dani Moncayo <dmoncayo <at> gmail.com>
Cc: Juri Linkov <juri <at> jurta.org>, 10906 <at> debbugs.gnu.org
Subject: Re: bug#10906: 24.0.94; `c-mark-function' does set the mark well
Date: Mon, 5 Mar 2012 18:41:33 +0000
Hello, Dani.

On Fri, Mar 02, 2012 at 12:03:48AM +0100, Dani Moncayo wrote:

> >> > Regarding bug#10906, I think `c-mark-function' should be rewritten
> >> > to follow the logic of `mark-defun'.

> > Any chance of a quick summary of how c-mark-function differs from
> > mark-defun?

> AFAIK, they differ at least in two things:

> 1. `mark-defun' saves the original point location in the mark ring,
> whereas `c-mark-function' does not.  IMO, the point should be saved,
> because in large defuns it may jump to a remote location and you may
> want to return back to the original position.  This bug report is
> about this inconsistency, as you can see in the original post.

> 2. Successive interactive invocations of `mark-defun' extend the
> region to the next defuns (which I find useful), whereas
> `c-mark-function' does not have this feature.  Bug #5525 is a request
> to remove this inconsistency, as you can see in the corresponding
> thread.

> >> Agreed, and BTW, if `c-mark-function' is going to be revised, please,
> >> take also this problem into account:

> >> http://debbugs.gnu.org/cgi/bugreport.cgi?bug=5525

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!


diff -r f6961b0b1c51 cc-cmds.el
--- a/cc-cmds.el	Fri Mar 02 21:25:40 2012 +0000
+++ b/cc-cmds.el	Mon Mar 05 18:35:18 2012 +0000
@@ -1966,8 +1966,20 @@
 
     (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)
+	      (goto-char (cdr (c-declaration-limits t)))
+	      (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).




This bug report was last modified 13 years and 133 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.