unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
To: Richard Riley <rileyrgdev@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Emacs standards with regions
Date: Wed, 26 Nov 2008 09:19:45 +0100	[thread overview]
Message-ID: <492D06A1.8080703@easy-emacs.de> (raw)
In-Reply-To: <ggefps$lmv$1@news.motzarella.org>

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





  parent reply	other threads:[~2008-11-26  8:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-24 15:03 Emacs standards with regions Richard Riley
2008-11-24 16:46 ` Xah Lee
2008-11-24 18:15   ` Xah Lee
2008-11-24 21:07     ` Eli Zaretskii
     [not found]     ` <mailman.1152.1227560873.26697.help-gnu-emacs@gnu.org>
2008-11-24 21:26       ` Richard Riley
2008-11-25  3:40     ` Jason Rumney
2008-11-25 10:16       ` Xah Lee
2008-11-25 15:55         ` Jason Rumney
2008-11-25 15:57           ` Richard Riley
2008-11-25 18:01             ` Reiner Steib
2008-11-25 20:31     ` Teemu Likonen
2008-11-25 20:47       ` Xah Lee
2008-11-25 23:55         ` Alan Mackenzie
2008-11-26  8:19 ` Andreas Röhler [this message]
     [not found] ` <mailman.1274.1227687564.26697.help-gnu-emacs@gnu.org>
2008-11-26 14:45   ` Xah Lee

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=492D06A1.8080703@easy-emacs.de \
    --to=andreas.roehler@easy-emacs.de \
    --cc=help-gnu-emacs@gnu.org \
    --cc=rileyrgdev@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.
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).