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

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

Re: Emacs standards with regions


From: Andreas Röhler
Subject: Re: Emacs standards with regions
Date: Wed, 26 Nov 2008 09:19:45 +0100
User-agent: Thunderbird 2.0.0.6 (X11/20070801)

Richard Riley wrote:
> Is there some reason that most emacs commands do not consider active
> region when invoked? One of the biggest UI improvements (for me) would
> be for interactive commands to default to the marked region.
>
> e.g C-s  for isearch-forward
>
> Hilite "word" and "word" is the default search term. Ditto for % (search
> and replace). I just modified my py-execute-buffer for example to call
> py-execute-region with the marked region rather than the entire buffer
> if the region was active. Why have a seperate "execute-region" command?
>
> The ignoring of the region in so many key commands makes we wonder if I
> am missnig a default setting or if there was a decision not to use the
> region.
>
> e.g this Google search function I use defaults
>
> ,----
> | (defun rgr/google-search-prompt()
> |   (interactive)
> |   (let* ((default (region-or-word-at-point))
> |      (term (read-string (format "Google the web for the following phrase 
> (%s): "
> |                                     default))))
> |     (message "term is %s. Length is %d" term (length term))
> |     (rgr/google (if (zerop(length term)) default term))
> |     ))
> `----
>
>
> Can anyone add to this?
>
>
>
>   

AFAIS we have to consider too different cases:

1) where the region is something like the thing searched for
2) the region marks the boundary wherein some action should take place.

You mentioned the first case. Relating to the second,
default values are not to define in general. Boundaries
may be every position, even if beginning- or
end-of-line or paragraph may occur quite often.

For my purposes I use a template, which inserts this in an assumed `let'

       ((beg (cond (beg beg)
           ((region-active-p)
            (region-beginning))
           (t (line-beginning-position))))
    (end (cond (end (copy-marker end))
           ((region-active-p)
            (copy-marker (region-end)))
           (t (copy-marker (line-end-position))))))


Afterwards I have to change (line-beginning-position)
etc., should it not be the right thing.

`region-active-p' is defined as

(unless (featurep 'xemacs)
  (defun region-active-p ()
    (and mark-active transient-mark-mode
     (not (eq (region-beginning) (region-end))))))


Andreas Röhler





reply via email to

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