all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* leaving the region highlighted after a command
@ 2007-06-06 13:24 Jonathan Swartz
  2007-06-06 15:15 ` Drew Adams
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Swartz @ 2007-06-06 13:24 UTC (permalink / raw)
  To: help-gnu-emacs

I use transient-mark-mode. I'm trying to write a command like mark- 
whole-buffer that selects a certain region and leaves it highlighted.  
But I cannot seem to get this to work; at the end of my command, the  
region is never highlighted.

Here's the definition of mark-whole-buffer in simple.el:

    (defun mark-whole-buffer ()
      "Put point at beginning and mark at end of buffer.
    You probably should not use this function in Lisp programs;
    it is usually a mistake for a Lisp function to use any subroutine
    that uses or sets the mark."
      (interactive)
      (push-mark (point))
      (push-mark (point-max) nil t)
      (goto-char (point-min)))

This leaves the region highlighted. But if I simply call mark-whole- 
buffer from another function or copy its code verbatim to another  
function, the new other functions do NOT leave the region highlighted:

    ;; No highlighting
    (defun mb ()
      (interactive)
      (mark-whole-buffer))

    ;; Yup, still no highlighting
    (defun mb2 ()
      "Put point at beginning and mark at end of buffer.
    You probably should not use this function in Lisp programs;
    it is usually a mistake for a Lisp function to use any subroutine
    that uses or sets the mark."
      (interactive)
      (push-mark (point))
      (push-mark (point-max) nil t)
      (goto-char (point-min)))

So is there something magical about mark-whole-buffer that isn't  
evident in the source? e.g. is it on a list of functions somewhere to  
leave the region highlighted?

I've reproduced this on both Emacs 22.0.50.1 on OS X, and Emacs  
21.3.1 on RHEL4.

Any help much appreciated,
Jon

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: leaving the region highlighted after a command
  2007-06-06 13:24 leaving the region highlighted after a command Jonathan Swartz
@ 2007-06-06 15:15 ` Drew Adams
  2007-06-06 19:25   ` Jonathan Swartz
  0 siblings, 1 reply; 5+ messages in thread
From: Drew Adams @ 2007-06-06 15:15 UTC (permalink / raw)
  To: Jonathan Swartz, help-gnu-emacs

> I use transient-mark-mode. I'm trying to write a command like mark-
> whole-buffer that selects a certain region and leaves it highlighted.
> But I cannot seem to get this to work; at the end of my command, the
> region is never highlighted.
>
> Here's the definition of mark-whole-buffer in simple.el:
>
>     (defun mark-whole-buffer ()
>       "Put point at beginning and mark at end of buffer.
>     You probably should not use this function in Lisp programs;
>     it is usually a mistake for a Lisp function to use any subroutine
>     that uses or sets the mark."
>       (interactive)
>       (push-mark (point))
>       (push-mark (point-max) nil t)
>       (goto-char (point-min)))
>
> This leaves the region highlighted. But if I simply call mark-whole-
> buffer from another function or copy its code verbatim to another
> function, the new other functions do NOT leave the region highlighted:
>
>     ;; No highlighting
>     (defun mb ()
>       (interactive)
>       (mark-whole-buffer))

Try (setq deactivate-mark nil).

I use something like this in some situations, in a particular post-command
hook:

(defun foo ()
  (when (not executing-kbd-macro) (setq deactivate-mark nil)))

In general, see the Elisp manual for `deactivate-mark'.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: leaving the region highlighted after a command
  2007-06-06 15:15 ` Drew Adams
@ 2007-06-06 19:25   ` Jonathan Swartz
  2007-06-07 14:30     ` Drew Adams
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Swartz @ 2007-06-06 19:25 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs


On Jun 6, 2007, at 8:15 AM, Drew Adams wrote:

>> I use transient-mark-mode. I'm trying to write a command like mark-
>> whole-buffer that selects a certain region and leaves it highlighted.
>> But I cannot seem to get this to work; at the end of my command, the
>> region is never highlighted.
>>
>> Here's the definition of mark-whole-buffer in simple.el:
>>
>>     (defun mark-whole-buffer ()
>>       "Put point at beginning and mark at end of buffer.
>>     You probably should not use this function in Lisp programs;
>>     it is usually a mistake for a Lisp function to use any subroutine
>>     that uses or sets the mark."
>>       (interactive)
>>       (push-mark (point))
>>       (push-mark (point-max) nil t)
>>       (goto-char (point-min)))
>>
>> This leaves the region highlighted. But if I simply call mark-whole-
>> buffer from another function or copy its code verbatim to another
>> function, the new other functions do NOT leave the region  
>> highlighted:
>>
>>     ;; No highlighting
>>     (defun mb ()
>>       (interactive)
>>       (mark-whole-buffer))
>
> Try (setq deactivate-mark nil).
>
> I use something like this in some situations, in a particular post- 
> command
> hook:
>
> (defun foo ()
>   (when (not executing-kbd-macro) (setq deactivate-mark nil)))
>
> In general, see the Elisp manual for `deactivate-mark'.
>
>

That did it! I still don't understand why my mb function doesn't work  
above, when all it does is call mark-whole-buffer...but adding  
deactivate-mark fixed it.

Thanks
Jon

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: leaving the region highlighted after a command
  2007-06-06 19:25   ` Jonathan Swartz
@ 2007-06-07 14:30     ` Drew Adams
  0 siblings, 0 replies; 5+ messages in thread
From: Drew Adams @ 2007-06-07 14:30 UTC (permalink / raw)
  To: help-gnu-emacs

> > (defun foo ()
> >   (when (not executing-kbd-macro) (setq deactivate-mark nil)))
> >
> > In general, see the Elisp manual for `deactivate-mark'.
>
> That did it! I still don't understand why my mb function doesn't work
> above, when all it does is call mark-whole-buffer...but adding
> deactivate-mark fixed it.

Did you "see the Elisp manual for `deactivate-mark'?"? That explains that

    "If an editor command sets this variable non-`nil', then the editor
     command loop deactivates the mark after the command returns (if
     Transient Mark mode is enabled).  All the primitives that change
     the buffer set `deactivate-mark', to deactivate the mark when the
     command is finished.
     To write Lisp code that modifies the buffer without causing
     deactivation of the mark at the end of the command, bind
     `deactivate-mark' to `nil' around the code that does the
     modification."

IOW, your code did not work because the marke was automatically deactivated
after your command returned.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: leaving the region highlighted after a command
       [not found] <mailman.1639.1181136259.32220.help-gnu-emacs@gnu.org>
@ 2007-06-10 10:15 ` Johan Bockgård
  0 siblings, 0 replies; 5+ messages in thread
From: Johan Bockgård @ 2007-06-10 10:15 UTC (permalink / raw)
  To: help-gnu-emacs

Jonathan Swartz <swartz@pobox.com> writes:

> But if I simply call mark-whole- buffer from another function or
> copy its code verbatim to another function, the new other functions
> do NOT leave the region highlighted:
>
>    ;; No highlighting
>    (defun mb ()
>      (interactive)
>      (mark-whole-buffer))

Works for me.

-- 
Johan Bockgård

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-06-10 10:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-06 13:24 leaving the region highlighted after a command Jonathan Swartz
2007-06-06 15:15 ` Drew Adams
2007-06-06 19:25   ` Jonathan Swartz
2007-06-07 14:30     ` Drew Adams
     [not found] <mailman.1639.1181136259.32220.help-gnu-emacs@gnu.org>
2007-06-10 10:15 ` Johan Bockgård

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.