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

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

Re: on adding a function call to a s-exp


From: Emanuel Berg
Subject: Re: on adding a function call to a s-exp
Date: Wed, 13 Jun 2018 18:48:31 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Távora wrote:

> DWIM guessing

One point regarding language: DWIM is far from
the computer "guessing" what the user wants!
Because the different actions are very
predictable based on the current state (which
is known, all clear and visible, and often part
of the workflow just one second ago), the Emacs
user is very aware of what is going on, and the
computer response is equally predictable!

Seeing the state is whatever it is, or setting
it up a certain way prior to invoking the DWIM
command, is thus part of executing the command
in the way that fits the situation!

So DWIM is a way to set up a natural, intuitive
workflow with less keys to memorize - it is not
the user being moronic, hitting the same key
for tons of purposes, and then have the
computer sweat in panic, trying to put together
something sensible of it!

There seems to be at least two definitions
of DWIM.

One is to do different things depending on if
some situation is or is not there. And it can
be based on something as simple as the position
of the cursor.

For example, in dired, if there is a file at
point, kill its path; if there isn't, kill the
path of the directory. As in:

    (defun dired-kill-path-dwim ()
      (interactive)
      (kill-new
       (or (dired-get-filename nil t)    ; kill file including path; or
           (dired-current-directory) ))) ; kill directory path if file u/a

The other, which is more undisputably DWIM, is
when you either use the region, or don't use
the region because there isn't one, and instead
fall back to a default behavior.

For example, to count the chars, if there is
a region, count the chars in the region, if
there isn't one, count the chars in the whole
buffer. As in:

    (defun count-chars (&optional start end)
      (interactive
       (if (use-region-p)
           (list (region-beginning) (region-end))
         (list (point-min) (point-max)) ))
      (message "%d" (- end start)) )

As you see, this is all-deterministic, no
guessing, and setting the state up is part of
executing the command. And that sounds
complicated and cool but actually it is
completely natural.

-- 
underground experts united
http://user.it.uu.se/~embe8573


reply via email to

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