From: Xah <xahlee@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: how to deal with comment in a new lang mode
Date: Sat, 1 Nov 2008 13:55:39 -0700 (PDT) [thread overview]
Message-ID: <250e7a38-f6fa-4dcb-93c7-7fc9c1c40339@b31g2000prb.googlegroups.com> (raw)
In-Reply-To: 1225553160.28988@arno.fh-trier.de
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/
☄
next prev parent reply other threads:[~2008-11-01 20:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-30 20:59 how to deal with comment in a new lang mode Xah
2008-10-31 2:46 ` Kevin Rodgers
2008-10-31 14:10 ` rgb
[not found] ` <mailman.2542.1225421198.25473.help-gnu-emacs@gnu.org>
2008-10-31 20:04 ` Xah
2008-11-01 12:53 ` Rupert Swarbrick
2008-11-01 13:47 ` Kevin Rodgers
[not found] ` <mailman.2630.1225547412.25473.help-gnu-emacs@gnu.org>
2008-11-01 14:41 ` Xah
2008-11-01 15:24 ` Andreas Politz
2008-11-01 20:55 ` Xah [this message]
2008-11-01 21:23 ` Andreas Politz
2008-11-01 21:48 ` Xah
2008-11-01 18:59 ` Rupert Swarbrick
2008-11-03 14:08 ` rgb
2008-11-03 14:19 ` rgb
2008-11-03 15:02 ` Seweryn Kokot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=250e7a38-f6fa-4dcb-93c7-7fc9c1c40339@b31g2000prb.googlegroups.com \
--to=xahlee@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.