unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* how to deal with comment in a new lang mode
@ 2008-10-30 20:59 Xah
  2008-10-31  2:46 ` Kevin Rodgers
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Xah @ 2008-10-30 20:59 UTC (permalink / raw)
  To: help-gnu-emacs

when writing a new language mode, how can one make comment-dwim work?

i can of course code my own functions dealing with comments, but i
think it is better to use the facilities provided in newcomment.el?

right now i have:

(defun xlsl-comment-dwim (arg)
  (interactive "*P")
  (let ((comment-start-orig comment-start)
        (comment-end-orig comment-end))
    (setq comment-start "// ")
    (setq comment-end "")
    (comment-dwim arg)

    (setq comment-start comment-start-orig)
    (setq comment-end comment-end-orig)
))

and

  (define-key xlsl-mode-map [remap comment-dwim] 'xlsl-comment-dwim)

this works fine when typing the shortcut for comment-dwim on a empty
line to insert comment. But doesnt work as expected when the line is
already a comment. (it does nothing)

any advice apprecated for dealing with comments in a new lang mode.

Thanks.

PS if it matters, i also have my syntax table defined:

(defvar xlsl-mode-syntax-table
  (let ((synTable (make-syntax-table)))
    (modify-syntax-entry ?\/ ". 12b" synTable)
    (modify-syntax-entry ?\n "> b" synTable)

    (modify-syntax-entry ?< "()" synTable)
    (modify-syntax-entry ?> ")(" synTable)
    synTable
    )
  "Syntax table for `xlsl-mode'."
)

The lsl has “// ...” as comment but not “/* ... */”. I dont want it to
be derived mode of c-mode though atm ...

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: how to deal with comment in a new lang mode
  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>
  2 siblings, 0 replies; 15+ messages in thread
From: Kevin Rodgers @ 2008-10-31  2:46 UTC (permalink / raw)
  To: help-gnu-emacs

Xah wrote:
> when writing a new language mode, how can one make comment-dwim work?
> 
> i can of course code my own functions dealing with comments, but i
> think it is better to use the facilities provided in newcomment.el?
> 
> right now i have:
> 
> (defun xlsl-comment-dwim (arg)
>   (interactive "*P")
>   (let ((comment-start-orig comment-start)
>         (comment-end-orig comment-end))
>     (setq comment-start "// ")
>     (setq comment-end "")
>     (comment-dwim arg)
> 
>     (setq comment-start comment-start-orig)
>     (setq comment-end comment-end-orig)
> ))
> 
> and
> 
>   (define-key xlsl-mode-map [remap comment-dwim] 'xlsl-comment-dwim)
> 
> this works fine when typing the shortcut for comment-dwim on a empty
> line to insert comment. But doesnt work as expected when the line is
> already a comment. (it does nothing)
> 
> any advice apprecated for dealing with comments in a new lang mode.

I can't address your question, but I can suggest a minor simplification
of your current implementation:

(defun xlsl-comment-dwim (arg)
   (interactive "*P")
   (let ((comment-start "// ")
         (comment-end ""))
     (comment-dwim arg)))

This is also has the advantage of restoring the original binding of
the comment-start and comment-end variables, even if comment-dwim
signals an error.

Hope that helps,

-- 
Kevin Rodgers
Denver, Colorado, USA





^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: how to deal with comment in a new lang mode
  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>
  2 siblings, 0 replies; 15+ messages in thread
From: rgb @ 2008-10-31 14:10 UTC (permalink / raw)
  To: help-gnu-emacs

On Oct 30, 3:59 pm, Xah <xah...@gmail.com> wrote:
> when writing a new language mode, how can one make comment-dwim work?
>
> i can of course code my own functions dealing with comments, but i
> think it is better to use the facilities provided in newcomment.el?
>
> right now i have:
>
> (defun xlsl-comment-dwim (arg)
>   (interactive "*P")
>   (let ((comment-start-orig comment-start)
>         (comment-end-orig comment-end))
>     (setq comment-start "// ")
>     (setq comment-end "")
>     (comment-dwim arg)
>
>     (setq comment-start comment-start-orig)
>     (setq comment-end comment-end-orig)
> ))
>
> and
>
>   (define-key xlsl-mode-map [remap comment-dwim] 'xlsl-comment-dwim)
>
> this works fine when typing the shortcut for comment-dwim on a empty
> line to insert comment. But doesnt work as expected when the line is
> already a comment. (it does nothing)
>
> any advice apprecated for dealing with comments in a new lang mode.
>
> Thanks.
>
> PS if it matters, i also have my syntax table defined:
>
> (defvar xlsl-mode-syntax-table
>   (let ((synTable (make-syntax-table)))
>     (modify-syntax-entry ?\/ ". 12b" synTable)
>     (modify-syntax-entry ?\n "> b" synTable)
>
>     (modify-syntax-entry ?< "()" synTable)
>     (modify-syntax-entry ?> ")(" synTable)
>     synTable
>     )
>   "Syntax table for `xlsl-mode'."
> )
>
> The lsl has “// ...” as comment but not “/* ... */”. I dont want it to
> be derived mode of c-mode though atm ...
>
>   Xah
> ∑http://xahlee.org/
>
> ☄

Comment DWIM uses the variable comment-start for EOL terminated
comments.
If comments must be explicitly terminated then set comment-end.
(set (make-local-variable 'comment-start) "#")
See newcomment.el



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: how to deal with comment in a new lang mode
       [not found] ` <mailman.2542.1225421198.25473.help-gnu-emacs@gnu.org>
@ 2008-10-31 20:04   ` Xah
  2008-11-01 12:53     ` Rupert Swarbrick
                       ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Xah @ 2008-10-31 20:04 UTC (permalink / raw)
  To: help-gnu-emacs


Xah Lee wrote:
> > when writing a new language mode, how can one make comment-dwim work?
>
> > i can of course code my own functions dealing with comments, but i
> > think it is better to use the facilities provided in newcomment.el?
> > ...
> > any advice apprecated for dealing with comments in a new lang mode.

Kevin Rodgers wrote:
> I can't address your question, but I can suggest a minor simplification
> of your current implementation:
>
> (defun xlsl-comment-dwim (arg)
>    (interactive "*P")
>    (let ((comment-start "// ")
>          (comment-end ""))
>      (comment-dwim arg)))
>
> This is also has the advantage of restoring the original binding of
> the comment-start and comment-end variables, even if comment-dwim
> signals an error.

Thanks, it did help.

i haven't tested extensively, but looks like the above is all i need.
My previous problem of comment-dwim not doing any commenting/
uncommenting when on a line such as:
“;; this and that.”
while the cursor on the line, is the consistant behavior of comment-
dwim.

Not sure i liked the behavior of comment-dwim... i haven't decided
yet, but it seems too smart or quite complex. For now i decided to
experiment since it's not too difficult.

;; implementation using “newcomment.el”. I don't like comment-dwim's
behavior. Its too “smart/complex”. In particular, when there's no
active region and current line is a comment, it doesn't do anything
except moving cursor.
;; (defun xlsl-comment-dwim (arg)
;;    (interactive "*P")
;;    ;; (require 'newcomment)
;;    (let ((comment-start "// ")
;;          (comment-end ""))
;;      (comment-dwim arg)))

;; implementation not using “newcomment.el”.
(defun xlsl-comment-dwim ()
  "Comment or uncomment the current line or text selection."
  (interactive)
  ;; If there's no text selection, comment or uncomment the line
depending whether the WHOLE line is a comment. If there is a text
selection, using the first line to determine whether to comment/
uncomment.
  (let (p1 p2)
    (if (and transient-mark-mode mark-active)
        (save-excursion
          (setq p1 (region-beginning) p2 (region-end))
          (goto-char p1)
          (if (wholeLineIsCmt-p)
          (xlsl-uncomment-region p1 p2)
          (xlsl-comment-region p1 p2)
          ))
      (progn
        (if (wholeLineIsCmt-p)
            (xlsl-uncomment-current-line)
          (xlsl-comment-current-line)
          ))
      )
    ))

(defun wholeLineIsCmt-p ()
  (save-excursion
      (move-beginning-of-line 1)
      (looking-at "[ \t]*//")
      )
 )

(defun xlsl-comment-current-line ()
  (interactive)
  (move-beginning-of-line 1)
  (insert "//")
  )

(defun xlsl-uncomment-current-line ()
  "Remove the string “//” in the beginning of current line."
  (interactive)
  (when (wholeLineIsCmt-p)
    (move-beginning-of-line 1)
    (search-forward "//")
    (delete-backward-char 2)
    )
  )

(defun xlsl-comment-region (p1 p2)
  "Add “//” to the beginning of each line of selected text."
  (interactive "r")
  (let ((deactivate-mark nil))
    (save-excursion
      (goto-char p2)
      (while (>= (point) p1)
        (xlsl-comment-current-line)
        (previous-line)
        )
      )
    )
  )

(defun xlsl-uncomment-region (p1 p2)
  "Remove “//” in the beginning of each line of selected text."
  (interactive "r")
  (let ((deactivate-mark nil))
    (save-excursion
      (goto-char p2)
      (while (>= (point) p1)
        (xlsl-uncomment-current-line)
        (previous-line)
        )
      )
    )
  )

took me about 3 hours. Coding this i realized there's some details,
more complex than i originally thought but still not much work.
Possibly down the road i'll go back to basing it on “newcomment.el”.

PS is there a command to compact the ending parens?

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: how to deal with comment in a new lang mode
  2008-10-31 20:04   ` Xah
@ 2008-11-01 12:53     ` Rupert Swarbrick
  2008-11-01 13:47     ` Kevin Rodgers
                       ` (3 subsequent siblings)
  4 siblings, 0 replies; 15+ messages in thread
From: Rupert Swarbrick @ 2008-11-01 12:53 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 252 bytes --]

Xah <xahlee@gmail.com> writes:

> PS is there a command to compact the ending parens?

Well, I tend to go to the last one and C-a C-\ <backspace>
repeatedly. Well in fact, it's usually
  C-x C-( C-a C-\ <backspace> C-x C-) C-x e e e e e .... e

Rupert

[-- Attachment #2: Type: application/pgp-signature, Size: 314 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: how to deal with comment in a new lang mode
  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>
                       ` (2 subsequent siblings)
  4 siblings, 0 replies; 15+ messages in thread
From: Kevin Rodgers @ 2008-11-01 13:47 UTC (permalink / raw)
  To: help-gnu-emacs

Xah wrote:
...
> (defun xlsl-uncomment-region (p1 p2)
>   "Remove “//” in the beginning of each line of selected text."
>   (interactive "r")
>   (let ((deactivate-mark nil))
>     (save-excursion
>       (goto-char p2)
>       (while (>= (point) p1)
>         (xlsl-uncomment-current-line)
>         (previous-line)
>         )
>       )
>     )
>   )
> 
> took me about 3 hours. Coding this i realized there's some details,
> more complex than i originally thought but still not much work.
> Possibly down the road i'll go back to basing it on “newcomment.el”.
> 
> PS is there a command to compact the ending parens?

C-M-% ) C-q C-j SPC + ) RET )) RET

-- 
Kevin Rodgers
Denver, Colorado, USA





^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: how to deal with comment in a new lang mode
       [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 18:59         ` Rupert Swarbrick
  0 siblings, 2 replies; 15+ messages in thread
From: Xah @ 2008-11-01 14:41 UTC (permalink / raw)
  To: help-gnu-emacs

On Nov 1, 6:47 am, Kevin Rodgers <kevin.d.rodg...@gmail.com> wrote:
> Xah wrote:
> ...
> > (defun xlsl-uncomment-region (p1 p2)
> >   "Remove “//” in the beginning of each line of selected text."
> >   (interactive "r")
> >   (let ((deactivate-mark nil))
> >     (save-excursion
> >       (goto-char p2)
> >       (while (>= (point) p1)
> >         (xlsl-uncomment-current-line)
> >         (previous-line)
> >         )
> >       )
> >     )
> >   )
> > ...

> > PS is there a command to compact the ending parens?

Kevin Rodgers wrote:
> C-M-% ) C-q C-j SPC + ) RET )) RET

Rupert Swarbrick wrote:
> Well, I tend to go to the last one and C-a C-\ <backspace>
> repeatedly. Well in fact, it's usually
>   C-x C-( C-a C-\ <backspace> C-x C-) C-x e e e e e .... e

ugh! I could have counted the parens, delete, then type them faster
than these methdos.

kinda interesting that almost 3 decades of emacs+elisp its still like
this.

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.

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: how to deal with comment in a new lang mode
  2008-11-01 14:41       ` Xah
@ 2008-11-01 15:24         ` Andreas Politz
  2008-11-01 20:55           ` Xah
  2008-11-01 18:59         ` Rupert Swarbrick
  1 sibling, 1 reply; 15+ messages in thread
From: Andreas Politz @ 2008-11-01 15:24 UTC (permalink / raw)
  To: help-gnu-emacs

Xah wrote:
> On Nov 1, 6:47 am, Kevin Rodgers <kevin.d.rodg...@gmail.com> wrote:
>> Xah wrote:
>> ...
>>> (defun xlsl-uncomment-region (p1 p2)
>>>   "Remove “//” in the beginning of each line of selected text."
>>>   (interactive "r")
>>>   (let ((deactivate-mark nil))
>>>     (save-excursion
>>>       (goto-char p2)
>>>       (while (>= (point) p1)
>>>         (xlsl-uncomment-current-line)
>>>         (previous-line)
>>>         )
>>>       )
>>>     )
>>>   )
>>> ...
> 
>>> PS is there a command to compact the ending parens?
> 
> Kevin Rodgers wrote:
>> C-M-% ) C-q C-j SPC + ) RET )) RET
> 
> Rupert Swarbrick wrote:
>> Well, I tend to go to the last one and C-a C-\ <backspace>
>> repeatedly. Well in fact, it's usually
>>   C-x C-( C-a C-\ <backspace> C-x C-) C-x e e e e e .... e
> 
> ugh! I could have counted the parens, delete, then type them faster
> than these methdos.
> 
> kinda interesting that almost 3 decades of emacs+elisp its still like
> this.
> 
> 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.
> 
>   Xah
> ∑ http://xahlee.org/
> 
> ☄
> 

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 ?

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.
`----


-ap


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: how to deal with comment in a new lang mode
  2008-11-01 14:41       ` Xah
  2008-11-01 15:24         ` Andreas Politz
@ 2008-11-01 18:59         ` Rupert Swarbrick
  1 sibling, 0 replies; 15+ messages in thread
From: Rupert Swarbrick @ 2008-11-01 18:59 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1810 bytes --]

Xah <xahlee@gmail.com> writes:

> On Nov 1, 6:47 am, Kevin Rodgers <kevin.d.rodg...@gmail.com> wrote:
>> Xah wrote:
>> > PS is there a command to compact the ending parens?
>
> Kevin Rodgers wrote:
>> C-M-% ) C-q C-j SPC + ) RET )) RET
>
> Rupert Swarbrick wrote:
>> Well, I tend to go to the last one and C-a C-\ <backspace>
>> repeatedly. Well in fact, it's usually
>>   C-x C-( C-a C-\ <backspace> C-x C-) C-x e e e e e .... e
>
> ugh! I could have counted the parens, delete, then type them faster
> than these methdos.
>
> kinda interesting that almost 3 decades of emacs+elisp its still like
> this.

Hmm, Andreas has a good point. And I consider myself to have got things
wrong if I've managed to get this to happen.

You might be interested to note that paredit not only makes it
reasonably hard to end up with icky trailing parens like this, but also
ignores it when you "backspace through a )". Thus, if you somehow end up
with code looking like yours, you can always just go to the end of the
function and press and hold backspace until you get back to the end of
the meat of the function.

So, there's silly hacks like mine and Kevin's, there's a neat (if
obscure) function that Andreas suggested and, if you're using "the
right" major mode, you don't have to think at all.

Maybe after almost 3 decades of emacs+elisp, the problem's been solved.

Rupert

P.S. Your habit of cross-posting to g.e.help and c.emacs was really
annoying me until I realised that replies tended to arrive on g.e.help,
so I got gnus to put the group higher up in the list. However, you could
always save the rest of the world the trouble by posting to a single
newsgroup.

P.P.S. I don't intend to get into any sort of flaming match, so a reply
about either this or the previous postscript will be ignored categorically.

[-- Attachment #2: Type: application/pgp-signature, Size: 314 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: how to deal with comment in a new lang mode
  2008-11-01 15:24         ` Andreas Politz
@ 2008-11-01 20:55           ` Xah
  2008-11-01 21:23             ` Andreas Politz
  0 siblings, 1 reply; 15+ messages in thread
From: Xah @ 2008-11-01 20:55 UTC (permalink / raw)
  To: help-gnu-emacs

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/^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: how to deal with comment in a new lang mode
  2008-11-01 20:55           ` Xah
@ 2008-11-01 21:23             ` Andreas Politz
  2008-11-01 21:48               ` Xah
  0 siblings, 1 reply; 15+ messages in thread
From: Andreas Politz @ 2008-11-01 21:23 UTC (permalink / raw)
  To: help-gnu-emacs

Xah wrote:
> 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.
> 

What I was trying to say is, that inserting parens in pairs does not
insert newlines. I don't see the connection.
Somehow you end up with newlines between your parentheses and then
you need to remove them. Why insert them in the first place ?
(rethorical question)

-ap

> 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/
> 
> ☄


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: how to deal with comment in a new lang mode
  2008-11-01 21:23             ` Andreas Politz
@ 2008-11-01 21:48               ` Xah
  0 siblings, 0 replies; 15+ messages in thread
From: Xah @ 2008-11-01 21:48 UTC (permalink / raw)
  To: help-gnu-emacs

On Nov 1, 2:23 pm, Andreas Politz <poli...@fh-trier.de> wrote:

> What I was trying to say is, that inserting parens in pairs does not
> insert newlines. I don't see the connection.
> Somehow you end up with newlines between your parentheses and then
> you need to remove them. Why insert them in the first place ?
> (rethorical question)

read my post man!

when you code by inserting parens and moving sexp as unit, you end up
having ending parens each may be indented and on separate lines.

the above sentence explain how the line break appears, which answers
your rethorical question.

as to why one'd want to code lisp while maintaining nesting
integrity... the short answer is that i think it's overall more
efficient than otherwise. Let me know if you'd like a more detailed
analysis or elaboration.

i consider my current keyboarding and command system for coding lisp
is perfect, except one thing. I want a command that will re-format
current block of code.
more detail given here:
http://xahlee.org/emacs/lisp_formatter.html

if this command is available, i don't need compact-paren because it'd
cover it.

i consider that a lisp editor missing this feature caused _major_
damage to the lisp language ... (for detail, see the section
“Automatic, Uniform, Universal, Source Code Display” at Fundamental
Problems of Lisp ( http://xahlee.org/UnixResource_dir/writ/lisp_problems.html
), for the relation between a regular syntax and source code
formatting.)

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: how to deal with comment in a new lang mode
  2008-10-31 20:04   ` Xah
                       ` (2 preceding siblings ...)
       [not found]     ` <mailman.2630.1225547412.25473.help-gnu-emacs@gnu.org>
@ 2008-11-03 14:08     ` rgb
  2008-11-03 14:19     ` rgb
  4 siblings, 0 replies; 15+ messages in thread
From: rgb @ 2008-11-03 14:08 UTC (permalink / raw)
  To: help-gnu-emacs


> PS is there a command to compact the ending parens?
>
>   Xah
> \xAD\xF4http://xahlee.org/
>

I wrote 2 functions

expand-trailing-parens & collect-trailing-parens

They are about half way down on my wikki page

http://www.emacswiki.org/cgi-bin/wiki/Rick_Bielawski


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: how to deal with comment in a new lang mode
  2008-10-31 20:04   ` Xah
                       ` (3 preceding siblings ...)
  2008-11-03 14:08     ` rgb
@ 2008-11-03 14:19     ` rgb
  2008-11-03 15:02       ` Seweryn Kokot
  4 siblings, 1 reply; 15+ messages in thread
From: rgb @ 2008-11-03 14:19 UTC (permalink / raw)
  To: help-gnu-emacs

> PS is there a command to compact the ending parens?
>
>   Xah
> \xAD\xF4http://xahlee.org/
>
When I work on code I like the closing parens to line up below the
matching open paren.
So I wrote a patch to calculate-lisp-indent that puts a closing paren
in the 'correct' column.

Then, because most people don't like all those closing parens on lines
by themselves, I wrote 2 other functions.

expand-trailing-parens & collect-trailing-parens

I think you want the collect-trailing-parens function but you might
like the expand function sometimes too.

There are no interdependencies so just grab whichever you like from my
wikki page.
These are about half way down the page.

http://www.emacswiki.org/cgi-bin/wiki/Rick_Bielawski


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: how to deal with comment in a new lang mode
  2008-11-03 14:19     ` rgb
@ 2008-11-03 15:02       ` Seweryn Kokot
  0 siblings, 0 replies; 15+ messages in thread
From: Seweryn Kokot @ 2008-11-03 15:02 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=shift_jis, Size: 1153 bytes --]

rgb <rbielaws@i1.net> writes:

>> PS is there a command to compact the ending parens?
>>
>>   Xah
>> ‡”http://xahlee.org/
>>
> When I work on code I like the closing parens to line up below the
> matching open paren.
> So I wrote a patch to calculate-lisp-indent that puts a closing paren
> in the 'correct' column.
>
> Then, because most people don't like all those closing parens on lines
> by themselves, I wrote 2 other functions.
>
> expand-trailing-parens & collect-trailing-parens
>
> I think you want the collect-trailing-parens function but you might
> like the expand function sometimes too.
>
> There are no interdependencies so just grab whichever you like from my
> wikki page.
> These are about half way down the page.
>
> http://www.emacswiki.org/cgi-bin/wiki/Rick_Bielawski

Thanks for these useful functions.

In Emacs 22 `etp' function works only when removing t argument:
(newline-and-indent t)  -->  (newline-and-indent)

Also it's better to add 2 optional arguments in to avoid unwanted messages

    (while (re-search-forward "^\\s *)" nil t) ; ctp fun

    (while (re-search-forward ")" nil t) ; etp fun

-- 
regards,
Seweryn





^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2008-11-03 15:02 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).