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

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

Re: Emacs Book Vs Emacs Manuals


From: Bob Proulx
Subject: Re: Emacs Book Vs Emacs Manuals
Date: Fri, 26 Jun 2015 23:02:13 -0600
User-agent: Mutt/1.5.23 (2014-03-12)

Rusi wrote:
> Emanuel Berg wrote:
> > %% (replace-regexp "^\\(.*&.*&\\).*&\\(.*\\)" "\\1\\2")
>
> 51 chars (ignoring that things like ^& are shift chords)
> 
> F3
> C-s & RET C-SPC C-s C-s RET C-w C-a C-n
> F4
> 
> 16 keystrokes counting each chord as 1 1/2 keys

I don't think keyboard golf is the best justification for something.
It helps.  But for me keyboard macros are simply more interactive.
They are a way to quickly multiply one keystroke into many.

But the above does make me realize that I often use keyboard macros
when the "shape" of the text is a factor in the editing of it.  Such
as when I need to make edits around something both above and below
it.  I might need to move a chunk of text up or down or otherwise
mutate it in unusual ways while editing.  During the keyboard macro I
can search for something, then search for something different, perhaps
several times to land on the right starting point.  Then I can move up
or down spatially to be where I want to be.  That is much harder to do
with regular expression.  I grew up with regular expressions and use
them all of the time.  But I use different tools at different times.

Here is a contrived example.  Split the buffer into two windows.

C-x 4 C-f /tmp/outfile RET
C-x o

Then set up this quick keyboard macro.

  C-s                   ;; isearch-forward-regexp
  \                     ;; self-insert-command
  ^                     ;; self-insert-command
  C-p                   ;; previous-line
  C-SPC                 ;; set-mark-command
  C-b                   ;; backward-char
  M-w                   ;; kill-ring-save
  C-n                   ;; next-line
  C-e                   ;; move-end-of-line
  C-x o                 ;; other-window
  C-y                   ;; yank
  C-x o                 ;; other-window

Run that on this following, C-x e, e, e, e, e, repeatedly executing
the macro and decode the (not so) secret message.

  the quick brown fox jumps over a lazy dog
                        ^
  the quick brown fox jumps over a lazy dog
                                 ^
  the quick brown fox jumps over a lazy dog
         ^
  the quick brown fox jumps over a lazy dog
             ^
  the quick brown fox jumps over a lazy dog
              ^
  the quick brown fox jumps over a lazy dog
                          ^
  the quick brown fox jumps over a lazy dog
     ^
  the quick brown fox jumps over a lazy dog
             ^
  the quick brown fox jumps over a lazy dog
              ^
  the quick brown fox jumps over a lazy dog
         ^
  the quick brown fox jumps over a lazy dog
          ^

Regular expressions are awesome.  But keyboard macros are awesome too.

Bob



reply via email to

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