unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Dani Moncayo <dmoncayo@gmail.com>
Cc: 10906@debbugs.gnu.org
Subject: bug#10906: 24.0.94; `c-mark-function' does set the mark well
Date: Wed, 7 Mar 2012 21:09:29 +0000	[thread overview]
Message-ID: <20120307210929.GA2486@acm.acm> (raw)
In-Reply-To: <CAH8Pv0ijhC-WzUhf371nvHNeR0G8AZF1TrHSSXkenpWDB7bjWw@mail.gmail.com>

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 <acm@muc.de> 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).





  reply	other threads:[~2012-03-07 21:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-28 12:36 bug#10906: 24.0.94; `c-mark-function' does set the mark well Dani Moncayo
2012-02-29  9:02 ` Dani Moncayo
2012-03-01 21:24   ` Alan Mackenzie
2012-03-01 23:03     ` Dani Moncayo
2012-03-01 23:13       ` Alan Mackenzie
2012-03-03 14:16       ` Alan Mackenzie
2012-03-05 18:41       ` Alan Mackenzie
2012-03-05 22:36         ` Dani Moncayo
2012-03-07 21:09           ` Alan Mackenzie [this message]
2012-03-07 21:37             ` Dani Moncayo
2012-03-09 16:49               ` Alan Mackenzie
2012-03-01 23:16     ` Glenn Morris
2012-03-01 23:19   ` Glenn Morris
2012-03-08 11:51 ` bug#10906: Bug #10906 - " Alan Mackenzie

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120307210929.GA2486@acm.acm \
    --to=acm@muc.de \
    --cc=10906@debbugs.gnu.org \
    --cc=dmoncayo@gmail.com \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).