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

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

Re: how to deal with comment in a new lang mode


From: Xah
Subject: Re: how to deal with comment in a new lang mode
Date: Sat, 1 Nov 2008 13:55:39 -0700 (PDT)
User-agent: G2/1.0

Xah wrote:
> > i suppose i or any could easily write up a command to compact ending
> > parens ... i wonder why it's not really done. I guess its because most
> > people type parens one by one (as opposed to pairs), so they never
> > ends up with hanging parens like above in the first place.

Andreas Politz wrote:
> However, I would probablly use this baby :
>
> ,----[ C-h k M-^ ]
> | M-^ runs the command delete-indentation
> |   which is an interactive compiled Lisp function in `simple.el'.
> | It is bound to M-^.
> | (delete-indentation &optional ARG)
> |
> | Join this line to previous and fix up whitespace at join.
> | If there is a fill prefix, delete it from the beginning of this line.
> | With argument, join this line to following line.
> `----

ah yes. That's the one i was looking for.

Andreas wrote:
> I think your conclusion is true, but as for the proposition (people type
> parens one by one), I think most people simply don't end up with this pattern
> of parentheses when they code lisp. Where did the newline come from
> anyway, especially since it is not desired ?

i always type paren in pairs (using a kbd shortcut), and i don't ever
manually delete sinle paren. They always move in pairs, so during my
elisp coding the nesting integrity is always maintained.

So, i have:
(global-set-key (kbd "H-t") (lambda () (interactive) (insert "()")
(backward-char 1)))

The “t” is the right hand's middle finger position on dvorak.
(qwerty's k)
The H is Hyper, which is the Windows key on my PC keyboard (used with
OSX).

plus mark-sexp (Ctrl+Alt+Space). (mark-sexp is recently replaced by a
singe Alt+8 using Nikolaj Schumacher's implementation of extend-
selection recently discussed here, which effectively covers the
functionality of mark-sexp.)

So, with inserting parens in pairs, mark-sexp, and copy/cut/paste, and
with ergo bindings for cursor moving shortcuts all under right hand,
these makes coding lisp a breeze.

Note: other sexp navigation commands are used sometimes:
(global-set-key (kbd "M-<up>") 'backward-up-list)
(global-set-key (kbd "M-<down>") 'down-list)
(global-set-key (kbd "M-<left>") 'backward-sexp)
(global-set-key (kbd "M-<right>") 'forward-sexp)
(global-set-key (kbd "M-S-<left>") 'backward-list)
(global-set-key (kbd "M-S-<right>") 'forward-list)

--------------------------------

ok, i just coded a compact-parens. Here it is. The code is not
formatted, so one can see the code shape resulted from a the method
lisp coding of maintaining nesting integrity.

(defun compact-parens ()
"Removing white spaces in ending parenthesises.
Removes white space from cursor point to end of code block (\n\n).
Or, act on a text selection."
(interactive)
(let (meat meatNew p1 p2)

(setq myword
         (if (and transient-mark-mode mark-active)
             (progn (setq p1 (region-beginning) ) (setq p2 (region-
end) ))
(save-excursion
(setq p1 (point) )
(search-forward-regexp "\n\n" nil t)
(setq p2 (- (point) 2))
)
           ))

(setq meat (buffer-substring-no-properties p1 p2))

(setq meatNew
(with-temp-buffer
(insert meat)
(goto-char (point-min))
  (while (search-forward-regexp "[ \t\n]+)[ \t\n]+" nil t) (replace-
match " )" t t))
(buffer-string)
))

(delete-region p1 p2)
(insert meatNew)
)


)


code haven't been tested much but should work...

  Xah
∑ http://xahlee.org/

☄


reply via email to

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