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: Xah Lee
Subject: Re: Emacs standards with regions
Date: Mon, 24 Nov 2008 08:46:17 -0800 (PST)
User-agent: G2/1.0

On Nov 24, 7:03 am, Richard Riley <rileyrg...@gmail.com> wrote:
> One of the biggest UI improvements (for me) would
> be for interactive commands to default to the marked region.

i feel exactly the same way. If emacs commands use active region as a
way for alternative behavior (similiar to many commands using Ctrl+u
to change behavior), i think that's a improvement.

almost all my own commands, will consider active region if there is
one, and act on that. There are about 30 of them. My examples
includes:

• lookup-google, lookup-php-ref, lookup-wikipedia, lookup-word-def,
lookup-word-definition

• amazon-linkify, blog-url-linkify, curve-linkify, elisp-ref-linkify,
emacs-ref-linkify, full-size-img-linkify, google-search-linkify, image-
linkify, java-ref-linkify, local-linkify, mathematica-ref-linkify, nks-
linkify, perldoc-ref-linkify, php-ref-linkify, povray-ref-linkify,
python-ref-linkify, source-linkify, wikipedia-linkify, youporn-search-
linkify, youtube-linkify, youtube-search-linkify

• make-backup, make-html-table, make-word-entry, make-wiki-entry, make-
time-mag-src

a very good example of this is a command that deal with letter cases.
Recently i wrote about it here:

• Usability Problems With Emacs's Letter-Case Commands
  http://xahlee.org/emacs/modernization_upcase-word.html

---------------------------------

«Is there some reason that most emacs commands do not consider active
region when invoked?»

I think the reason is that, transient-mark-mode, and thus the concept
of active-region (i.e. known as Text Selection in modern terminology),
is a later add on. I'm guessing it is added in late 1990s or perhaps
after 2000. It is a add-on as some kinda compatibility with modern UI,
and probably is not considered as the emacs's way by most emacs
developers.

does anyone know when did transient-mark-mode come to emacs?

Even today, Richard Stallman is still rather anti transient-mark-mode.
(if you read emacs dev, he doesn't use it) For example, recently i
filed a bug report about delete-selection-mode, here:

Subject: bug#1120: issues on (put 'insert-date 'delete-selection t)
http://groups.google.com/group/gnu.emacs.bug/browse_frm/thread/ba8ab4a5223591b7

In the discussion, i wrote:
«
For elisp programers who wish to write extentions where the command's
behaviors change depending on whether user has delete-selection-mode
on, what should they do? Check for mark-active and delete-selection-
mode before any call to the insert function?

also, the current behavior seems to introduce a complexity, where
command behaves differently depending on whether it is invoked by a
keybinding or by M-x.
»

and Richard Stallman wrote:

«If you really want to make behavior depend on those variables, you
need to check them.  Whether you check them before or after calling
`insert' is up to you.  But that seems like a strange thing to do.»

The thread where this is discussed is here:
Subject: (insert ...) won't respect delete-selection-mode
Date: 2008-10-07
http://groups.google.com/group/gnu.emacs.help/browse_frm/thread/8cc49311d17b2a71

-----------------

I have put a lot thought in this issue, which of the 2 behaviors on
the region is superior in some technical sense (while disregard all
issues about “Modern UI” or “Standard practice”). Supeior here means
aspects of user operative efficiency, and power/flexibilty of commands
using one or the other paradigm.

To be precise, here's 2 behavior considered:

(1) The emacs traditional way. Namely, there is always a region, and
commands that might be useful to work on region, will have few choices
of interface: (A) have multiple versions of the command, one ending in
“-region”. (B) using universal argument mechanism (Ctrl+u) to specify
whether the command acts on region.

(note: a region in emacs is from last mark to current cursor position,
and there is always a region as soon as user did a mark once in a
buffer)

(2) The modern UI practice, meaning, a region in emacs can be active
or inactive. For commands that might be useful to consider applying to
the region, it has these choices: (A) same as above. (B) same as
above. (C) Act on region if there is a active region (aka text
selection).

Now, notice, that majority of emacs's commands use paradigm (1).
However, some of emacs's commands, do use paradim (2) and (C). For
example, comment-dwim is a good example.

I haven't studied this extensively, but basically, i think (C)
behavior is the superior one, that is: it is faster to invoke (less
keystrokes, regardless what easy key shortcuts you may have setup),
more intuitive to vast majority of computer users today, involves less
thinking.

Also note, for paradigm (2), it means that you must have transient-
mark-mode or cua-mode on. In other words, if you never use or want
region highlighting, you'll not find any possibly extra benefit of
commands that uses paradigm (2).

As noted before, transient-mark-mode and cua-mode are not on by
default, and they both are added to emacs as some compatibility mode,
and it is reasonable to assume that most emacs developers don't
consider them genuine “emacs way”, thus i think that's the reason
paradigm (2) is not much used in emacs even for newer packages.

i heard that in the current dev version of emacs, cua-mode is on by
default. I think that might usher more emacs commands to use paradigm
(2)...

-----------------------------
Note that the main purpose of transient-mark-mode is to have region
highlight, and in emacs, this cannot be possible without introducing
the concept of active region. But now, with the concept of active
region, it necessarily divide command UI paradigm into 2 groups, one
that is the emacs's traditional way of always having a region, as the
above paradigm (1), vs one that consider region as active/inactive as
above (2).

In short, in order to maintain emacs's traditional concept of region,
and in order to have region highlighting, spawned the 2 UI paradigms
that are not necessarily consistant with each other. If you want the
feature of region highlighting yet not obsolete the traditional
concept of emacs region and with it htousands of existing commands,
then these 2 not-necessarily consistent UI paradigms are inevitable.

In a ideal world, i would say it'd be better to exam and change the
few thousand of emac's commands so that they all consider active
region, and as a consequence possibly reducing tens of them. But this
is not realistic. On the other hand, i do not think it would introduce
any practical UI inconsistency if more commands starts to consider
active region.

-----------------------------

one thing i personally want is to have isearch automatically use the
current text selection for search. (this is a frequently asked
question) I tried to write my own custome function to do this but it
turns out not easy ...

as long as transient-mark-mode is not on by default, much of the above
thoughts won't even be possible. With cua-mode on by default in the
next version of emacs, i think that's a giant step forward.

------------------------------
«important and urgent problems of the technology of today are no
longer the satisfactions of the primary needs or of archetypal wishes,
but the reparation of the evils and damages by the technology of
yesterday.  ~Dennis Gabor, Innovations:  Scientific, Technological and
Social, 1970»

Great words!

... looking up Wikipedia, here's the url:
http://en.wikipedia.org/wiki/Dennis_Gabor

... bah, spent too much time writing this post... Sorry for the
wordiness.

  Xah
∑ http://xahlee.org/

☄

On Nov 24, 7:03 am, Richard Riley <rileyrg...@gmail.com> 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?
>
> --
>  important and urgent problems of the technology of today are no longer the 
> satisfactions of the primary needs or of archetypal wishes, but the 
> reparation of the evils and damages by the technology of yesterday.  ~Dennis 
> Gabor, Innovations:  Scientific, Technological and Social, 1970



reply via email to

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