Re: An Emacs command to close the various balanced expressions in Clojure
That's really is a cool idea of feature. I intend to add such a feature as well in ccw, will certainly be a very useful command in the default mode ! (and also in the REPL ? hmmm ) 2010/9/30 blais bl...@furius.ca It's too small to be an Emacs package, but I've forked it into its own file and a few improvements have been made to it. Here: http://furius.ca/pubcode/pub/conf/common/elisp/blais/close-matching.el ( It is linked from this page: http://furius.ca/pubcode/ ) On Sep 28, 6:03 pm, .Bill Smith william.m.sm...@gmail.com wrote: Blais, Thank you for contributing the emacs code. I have been looking for the same thing, for the reasons you and Laurent PETIT described. Bill Smith Austin, Texas -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: An Emacs command to close the various balanced expressions in Clojure
It's too small to be an Emacs package, but I've forked it into its own file and a few improvements have been made to it. Here: http://furius.ca/pubcode/pub/conf/common/elisp/blais/close-matching.el ( It is linked from this page: http://furius.ca/pubcode/ ) On Sep 28, 6:03 pm, .Bill Smith william.m.sm...@gmail.com wrote: Blais, Thank you for contributing the emacs code. I have been looking for the same thing, for the reasons you and Laurent PETIT described. Bill Smith Austin, Texas -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: An Emacs command to close the various balanced expressions in Clojure
Hi, blais is not talking 'bout openings, but closings. When you have this (the pipe symbol for the cursor position) : (def | foo [bar baz] (hello ) ) If you type ) You will have with paredit the cursor which jumps after the last closing paren, instead of just inserting this damn closing paren you wanted (it may not make sense for paredit, but maybe it makes sense for the typer : he's not in full control anymore). 2010/9/27 CuppoJava patrickli_2...@hotmail.com I'm curious what you don't like about the automatic insertion scheme that you talked about. I'm using Parenedit with emacs and I'm quite happy with it. I think the scheme is quite simple... whenever you type '(', it inserts ')'. Similarly with '[' and '{'. -Patrick On Sep 26, 7:51 pm, blais bl...@furius.ca wrote: Hi, Writing Clojure code tends to require a larger mix of (), [] and {} characters than other LISPs I use. This sometimes makes it a bit tiring to write those balanced expressions. Writing balanced expressions has been addressed in editors mainly by providing the automated insertion of matching characters when you type an opening character. This kind of support usually also comes with a fancy overloading of the default insertion behaviour of those characters to automatically skip extraneous ones, locking you into keeping everything balanced all the time; I find this extremely distracting and annoying to use, because it changes the behaviour I expect from my editor (it doesn't *always* insert, it is deeply troubling to me). I've tried it, and I could not get used to it. I came up with what I see as a better solution, and it feels right to me: a simple command to automatically insert the correct closing character at the current cursor location. For example, invoking the same command 4 times when the cursor is at the '|' location in the following expression will do the right thing: (comment (use '[merced.testinput :only (protocol| results in: (comment (use '[merced.testinput :only (protocol)])) One advantage of this approach is the absence of modality, i.e., the behaviour is the same in all contexts, e.g. when I type to insert, it always inserts. The new command means insert to close the sequence here, whatever the sequence character is. If you want to try it, here is the corresponding Emacs code: (defvar close-matching-chars '( (?( . ?)) (?[ . ?]) (?{ . ?}) (? . }) )) (defun close-matching () Close with the most appropriate matching balanced character. (interactive) ;; Scan backwards until it stops. (let ((c (save-excursion (while (ignore-errors (forward-sexp -1) (not (= (point) 1 (backward-char 1) (string-to-char (thing-at-point 'char)) ))) (insert-char (cdr (assoc c close-matching-chars)) 1) )) Bind it to your favourite key (I use 'Ctrl-)' ): (global-set-key [(control \))] 'close-matching) Have fun, -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: An Emacs command to close the various balanced expressions in Clojure
2010/9/27 Tassilo Horn tass...@member.fsf.org Hi, did you already try out paredit [1]? That mode is absolutely fabulous for programming any lisp and provides much more than just closing parens. My bet is that it's exactly paredit's behavior the OP is complaining about. We had the same discussions in counterclockwise, when I introduced paredit behavior. The problem is not that paredits commands aren't useful. They are ! The problem is that certain people don't want any paredit command bound to regular keystrokes. They want paredit out of their way when they are typing. They just want paredit commands accessible through command shortcuts. Think vim-like processing : when in typing mode, you cannot invoke any command available. You must enter the command mode before entering commands. We found *a* solution for Counterclockwise : The Structural edition (aka paredit's) commands are always available in the editor via keyboard shortcuts, but there are two modes: * the default mode : (default as in configured by default in a fresh ccw installation) *no* command is bound to regular keystrokes. a ( inserts a ( (and not its balanced )). a ] inserts a ] (and does not jump to the end of the closing enclosing form). Period. * the strict mode : (strict as in does its best to always confine/guide the user into strict structural edition) . In this mode, you guessed it, you get the usual paredit commands bound to keystroke, plus some extras : do a valid selection of form or sibling forms: hit some opening paren ( [ { and it automatically wraps the selected form(s) with the appropriate kind of brackets. etc. In ccw, even in strict mode, you can go away from the strict mode for the following keystroke: just hit escape and the next keystroke will bypass strict mode's command binding. Finally, you can jump back and forth default/strict mode via the Alt+D keyboard shortcut. Sorry if in the end of my answer I somehow hijacked the thread, but I thought this may be of interest to some. -- Laurent Give it a shot! Bye, Tassilo Footnotes: [1] http://mumble.net/~campbell/emacs/paredit.el -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: An Emacs command to close the various balanced expressions in Clojure
The message below pretty much sums it up. My original problem with paredit and such is that it creates modality, that is, the behaviour of insertion depends on the context. This variable behaviour, this modality problem is what Jef Raskin talks about in The Humane Interface (a truly enlightening book BTW). This is what makes us slow at using certain programs. In other words, when I type a character to insert, I want it to always insert; this behaviour is predictable and causes the least amout of surprise. Also, I feel that the command I submitted deals with 90% of the missing feature support I need for writing balancing expressions; everything else is trivial IMO (Emacs already deals with indenting, skipping and selection of balanced expressions better than anything else). I'm sure you can get used to anything though, but in my very personal experience, the less magic, the better. Feel free to use or discard, but if you install it I'll bet it'll grow on you. On Sep 28, 4:07 am, Laurent PETIT laurent.pe...@gmail.com wrote: 2010/9/27 Tassilo Horn tass...@member.fsf.org Hi, did you already try out paredit [1]? That mode is absolutely fabulous for programming any lisp and provides much more than just closing parens. My bet is that it's exactly paredit's behavior the OP is complaining about. We had the same discussions in counterclockwise, when I introduced paredit behavior. The problem is not that paredits commands aren't useful. They are ! The problem is that certain people don't want any paredit command bound to regular keystrokes. They want paredit out of their way when they are typing. They just want paredit commands accessible through command shortcuts. Think vim-like processing : when in typing mode, you cannot invoke any command available. You must enter the command mode before entering commands. We found *a* solution for Counterclockwise : The Structural edition (aka paredit's) commands are always available in the editor via keyboard shortcuts, but there are two modes: * the default mode : (default as in configured by default in a fresh ccw installation) *no* command is bound to regular keystrokes. a ( inserts a ( (and not its balanced )). a ] inserts a ] (and does not jump to the end of the closing enclosing form). Period. * the strict mode : (strict as in does its best to always confine/guide the user into strict structural edition) . In this mode, you guessed it, you get the usual paredit commands bound to keystroke, plus some extras : do a valid selection of form or sibling forms: hit some opening paren ( [ { and it automatically wraps the selected form(s) with the appropriate kind of brackets. etc. In ccw, even in strict mode, you can go away from the strict mode for the following keystroke: just hit escape and the next keystroke will bypass strict mode's command binding. Finally, you can jump back and forth default/strict mode via the Alt+D keyboard shortcut. Sorry if in the end of my answer I somehow hijacked the thread, but I thought this may be of interest to some. -- Laurent Give it a shot! Bye, Tassilo Footnotes: [1] http://mumble.net/~campbell/emacs/paredit.el -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: An Emacs command to close the various balanced expressions in Clojure
On Sep 26, 2010, at 6:51 PM, blais wrote: Writing Clojure code tends to require a larger mix of (), [] and {} characters than other LISPs I use. This sometimes makes it a bit tiring to write those balanced expressions. For outer expressions I tend to use the verbose forms (hash-map ...) and (vector ...) for aesthetic reasons, so {} and [] mostly occur around innermost expressions in my code. Then balancing the remaining parens is just a matter of hitting ')' until Vim highlights the outermost paren for me. But I might find a feature like yours useful; does anybody know of an equivalent for Vim? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: An Emacs command to close the various balanced expressions in Clojure
Hi, Am 28.09.2010 um 19:07 schrieb Michael Gardner: Does anybody know of an equivalent for Vim? Not yet, but it is on the radar for VC now. :) Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: An Emacs command to close the various balanced expressions in Clojure
Blais, Thank you for contributing the emacs code. I have been looking for the same thing, for the reasons you and Laurent PETIT described. Bill Smith Austin, Texas -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: An Emacs command to close the various balanced expressions in Clojure
I'm curious what you don't like about the automatic insertion scheme that you talked about. I'm using Parenedit with emacs and I'm quite happy with it. I think the scheme is quite simple... whenever you type '(', it inserts ')'. Similarly with '[' and '{'. -Patrick On Sep 26, 7:51 pm, blais bl...@furius.ca wrote: Hi, Writing Clojure code tends to require a larger mix of (), [] and {} characters than other LISPs I use. This sometimes makes it a bit tiring to write those balanced expressions. Writing balanced expressions has been addressed in editors mainly by providing the automated insertion of matching characters when you type an opening character. This kind of support usually also comes with a fancy overloading of the default insertion behaviour of those characters to automatically skip extraneous ones, locking you into keeping everything balanced all the time; I find this extremely distracting and annoying to use, because it changes the behaviour I expect from my editor (it doesn't *always* insert, it is deeply troubling to me). I've tried it, and I could not get used to it. I came up with what I see as a better solution, and it feels right to me: a simple command to automatically insert the correct closing character at the current cursor location. For example, invoking the same command 4 times when the cursor is at the '|' location in the following expression will do the right thing: (comment (use '[merced.testinput :only (protocol| results in: (comment (use '[merced.testinput :only (protocol)])) One advantage of this approach is the absence of modality, i.e., the behaviour is the same in all contexts, e.g. when I type to insert, it always inserts. The new command means insert to close the sequence here, whatever the sequence character is. If you want to try it, here is the corresponding Emacs code: (defvar close-matching-chars '( (?( . ?)) (?[ . ?]) (?{ . ?}) (? . }) )) (defun close-matching () Close with the most appropriate matching balanced character. (interactive) ;; Scan backwards until it stops. (let ((c (save-excursion (while (ignore-errors (forward-sexp -1) (not (= (point) 1 (backward-char 1) (string-to-char (thing-at-point 'char)) ))) (insert-char (cdr (assoc c close-matching-chars)) 1) )) Bind it to your favourite key (I use 'Ctrl-)' ): (global-set-key [(control \))] 'close-matching) Have fun, -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: An Emacs command to close the various balanced expressions in Clojure
Hi, did you already try out paredit [1]? That mode is absolutely fabulous for programming any lisp and provides much more than just closing parens. Give it a shot! Bye, Tassilo Footnotes: [1] http://mumble.net/~campbell/emacs/paredit.el -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: An Emacs command to close the various balanced expressions in Clojure
Thank you blais --- I also have troubles with paredit and this function will really help me out. keep up the good work, --Robert McIntyre On Sun, Sep 26, 2010 at 8:19 PM, Tassilo Horn tass...@member.fsf.org wrote: Hi, did you already try out paredit [1]? That mode is absolutely fabulous for programming any lisp and provides much more than just closing parens. Give it a shot! Bye, Tassilo Footnotes: [1] http://mumble.net/~campbell/emacs/paredit.el -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en