help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: leaving the region highlighted after a command


From: Jonathan Swartz
Subject: Re: leaving the region highlighted after a command
Date: Wed, 6 Jun 2007 12:25:02 -0700


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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]