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

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

Re: fill comma separated list


From: Kaushal Modi
Subject: Re: fill comma separated list
Date: Thu, 02 Jun 2016 17:47:48 +0000

On Thu, Jun 2, 2016 at 1:14 PM Jorge A. Alfaro-Murillo <
jorge.alfaro-murillo@yale.edu> wrote:

>
> Let's play emacs golf: (I assume no whitespace and cursor at the
> initial 5):
>
> F3 C-e <space> C-d C-e <space> C-d C-e <backspace> C-n C-a F4 C-0
> F4
>
> 14 key strokes.
>

http://i.imgur.com/dTdQRiG.gifv
Only the C-n key is not shown logged in the gif. But here is what I did

With cursor at the initial 5,

(1) F3
(2,3) M-4 M-^ (In fact, I have bound the functionality of C-u M-^ to C-j
[see below])
(4,5) M-4 M-^
(6) C-n
(7,8) M-0 F4 (you do not need to hit F4 and then do M-0 F4)

8 keys (10 keys, if adding the 2 spaces)
I count M-4/M-0 as single keystrokes as I use the Alt key, not Esc. That
should be OK? :)

=====

If interested, I bind C-j to below:

(defun modi/pull-up-line ()
  "Join the following line onto the current one (analogous to `C-e', `C-d')
or
`C-u M-^' or `C-u M-x join-line'.

If the current line is a comment and the pulled-up line is also a comment,
remove the comment characters from that line."
  (interactive)
  (join-line -1)
  ;; If the current line is a comment
  (when (nth 4 (syntax-ppss))
    ;; Remove the comment prefix chars from the pulled-up line if present
    (save-excursion
      ;; Delete all comment-start and space characters
      (while (looking-at (concat "\\s<" ; comment-start char as per syntax
table
                                 "\\|" (substring comment-start 0 1) ;
first char of `comment-start'
                                 "\\|" "\\s-")) ; extra spaces
        (delete-forward-char 1))
      (insert-char ? )))) ; insert space

-- 

-- 
Kaushal Modi


reply via email to

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