[Top][All Lists]

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

Re: Errors in interactive commands

From: Stephen J. Turnbull
Subject: Re: Errors in interactive commands
Date: Thu, 04 Aug 2011 11:15:16 +0900

Andreas Röhler writes:

 > > and you need to define it and show that there is a unified
 > > definition powerful enough to make it worthwhile to introduce a
 > > backward-incompatible change.


 > for example the implemented form forward-word already sends nil,
 > not error, when buffer-end is reached. Remains still to get it
 > messaged.
 > Thus implemented forward-word would allow a similar writing as
 > below.

Sure.  You said that already, you should assume we understand that.
(Especially since XEmacs already specifies `forward-word' to fail with
nil rather than an error at buffer boundaries, you should assume that
I know that.  Even though Emacs rarely worries more than a plugged
nickel about XEmacs compatibility, I think in this case it's actually
the strongest argument you have.  Ie, the backward compatibility
problem is probably hardly important.  Search for `(featurep 'xemacs)'
near `forward-word' to verify.)

Now we have two use cases, one of which needs the error, and one of
which prefers a null return.  That fails the "unified" test (see my
partial quote reproduced above).

If you want to use this idiom, it is easy, though somewhat inefficent,
to get your desired behavior via

(defun my-forward-word (&optional COUNT BUFFER)
  "exercise for the the reader"
  (condition-case nil
    ((beginning-of-buffer end-of-buffer) nil)

If you do this a lot, it's trivial to implement a macro.

I really don't think it's worth your while to fight this.

 > (defun my-collects ()
 >   "Report and return all word boundaries in current buffer, a list. "
 >    (interactive)
 >    (goto-char (point-min))
 >    (let ((positions-reached nil)
 >          (word-bounderies nil)
 >          erg bnds)
 >      (while (setq erg (ar-forward-word-atpt))
 >        (add-to-list 'positions-reached erg)
 >        (setq bnds (ar-bounds-of-word-atpt))
 >        (add-to-list 'word-bounderies bnds))
 >      (when (interactive-p) (message "positions-reached: %s" 
 > positions-reached))
 >      (when (interactive-p) (message "word-bounderies: %s" word-bounderies))
 > ;;    positions-reached
 >      word-bounderies
 >      ))
 > Just try to write that with means commonly available.

It's trivial, of course.  For the single line containing "while",

(while (and (save-excursion (skip-syntax-forward "^w") (not (eobp)))
            (setq erg (ar-forward-word-atpt)))

Of course it's prettier with `forward-word' specified your way, but
similarly the case I have in mind where partial failure of multiple
unit movement is an invalid state, not a termination condition, is
prettier with the current definition.

reply via email to

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