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

New command suggestion



    Date: 21 Jul 1984  20:44 EDT (Sat)
    From: Scott Layson <X.GYRO@MIT-OZ>

    This is a really handy command I invented for the FinalWord editor.
    FW users are so fond of it that I thought someone might want to add it
    to Zmacs.  I bind it to c-C, which (as far as I know) has never been
    bound in the default system.

I'm curious why people find this command useful (don't misunderstand --
I'm not denying that they do).  Is it because it works on the previous
word so easily, saving one the trouble of typing c--?  Or are
uppercasing and lowercasing and capitalizing similar enough that it's
easier to try this command until you get the look you wanted than
remember the correct command?

    Is there some more appropriate mailing list for messages of this kind?

Nope, this is the right one.

    (defcom com-rotate-case
	    "Change case of current/previous word.  Try it, it undoes itself.
    If the cursor is on a word, this command rotates the case of the word (starting
    at the current cursor position) from lowercase to capitalized to uppercase and
    back to lowercase.  If the cursor is not on a word, the command works on the 
    beginning of the previous word." ()
      (let ((point (point))
	    (save-point (copy-bp (point))))
	(if (not (= (word-syntax (bp-ch-char point)) word-alphabetic))
	    (move-bp point (or (forward-word point -1) (barf))))
	(setq *numeric-arg* 1)
	(let ((this-ch (bp-ch-char point))
	      (next-ch (bp-ch-char (forward-char point))))
	  (if (is-lowercase this-ch)
	      (com-uppercase-initial)
	      (if (is-lowercase next-ch)
		  (com-uppercase-word)
		  (com-lowercase-word)))
	  (move-bp (point) save-point)
	  dis-text)))

This command really doesn't undo itself, for example if applied to
FinalWord.  Not that it should, but the documentation claims that it
does.

The lowercase determination isn't hairy enough.  Some word-alphabetic
characters aren't letters.  For example, this command is a no-op on the
word "105foobar".  m-C would capitalize the "f".

A command that doesn't move point as part of its user interface
shouldn't move it internally.  Instead, you should compute BP's for the
range you want to operate in and call subroutines rather than the actual
commands.  What you did is unfortunately often easier without any
extension writers tools.

Why should an argument be ignored?