* marrying braket for ?: operator @ 2005-07-28 5:20 Baloff 2005-07-28 7:48 ` Alan Mackenzie 0 siblings, 1 reply; 7+ messages in thread From: Baloff @ 2005-07-28 5:20 UTC (permalink / raw) Hello when I move my pointer to a braket, it highlight its marring braket. but how can I get it to do the same with the ternary if-else operator (?:) I hope this is a good group for this question otherwise please point me. -------------------------------------------------- say this .cpp file for example (i < 10)? \\open 1 (i > 5)? \\open 2 cout << "5 < i < 10" << endl : \\close 2 cout << "i <= 5" << endl : \\close 1 cout << "i >= 10" << endl; -------------------------------------------------- the files below have been copied from some source I don't remember, and I am not lisp boy at all. I am coding c++ using emacs and have (load "~/.emacs-mc394") in my ~/.emacs ~/.emacs-mc394 looks like this ************************************************** ;; Modified by Mike Hvidsten from MC38J emacs file ;; Feb. 4, 2004 (c-add-style "mc394-style" '("cc-mode" (c-basic-offset . 3) ; In general, indent 3 spaces (c-hanging-braces-alist (defun-open after)) ; brace that opens a function definition (c-cleanup-list brace-else-brace brace-elseif-brace empty-defun-braces defun-close-semi scope-operator) (c-hanging-braces-alist ; These determine whether a newline appears before ; and/or after a brace in various situations. (brace-list-open) (block-open after) ; statement block open brace (defun-open after) ; brace that opens a function definition (substatement-open after); the brace that opens a substatement block (block-close . c-snug-do-while)) (c-hanging-colons-alist (access-label after)) ; Newline after protected: or private: (c-hungry-delete-key t))) ; delete black space all at once ;; Variable should be t if we are running xemacs. (defvar xemacs-p (string-match "XEmacs" emacs-version)) (if (not xemacs-p) (progn (global-font-lock-mode t) ; If using global-font-lock-mode, make control-L update colors (global-set-key "\C-l" (function (lambda (arg) (interactive "P") (font-lock-fontify-block 100) (recenter arg)))))) (setq auto-mode-alist (append '(("\\.h$" . c++-mode)) auto-mode-alist)) ************************************************** ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: marrying braket for ?: operator 2005-07-28 5:20 marrying braket for ?: operator Baloff @ 2005-07-28 7:48 ` Alan Mackenzie 2005-07-28 20:06 ` Robert Marshall 0 siblings, 1 reply; 7+ messages in thread From: Alan Mackenzie @ 2005-07-28 7:48 UTC (permalink / raw) Baloff <washdc@wash.edu> wrote on 28 Jul 2005 15:20:51 +1000: > Hello > when I move my pointer to a braket, it highlight its marrying braket. > but how can I get it to do the same with the ternary if-else operator > (?:) I hope this is a good group for this question otherwise please > point me. It's exactly the right group! There is no command which jumps from a ? to it's : or vice versa. Maybe there should be one. Maybe somebody, somewhere, has implemented one, and will jump in here with a URL pointing to the source code. The thing is, though, how useful would this command be? Programmers tend not to nest these conditional expressions very much. The command would have to bound to a key sequence, something like C-c : (that's "control-c colon"). By the time you've typed that in, you could just as well have found the colon by interactive search by typing C-s :. A tip: When you're asking questions like this, it's a good idea to write "C++ Mode" in the subject line (or even in the body of your post), so that people interested in C++ can zoom in quickly, and those not interested can ignore it quickly. ;-) And thanks for printing your CC Mode configuration settings. Even though it turned out it wasn't relevant here, it's often very useful. -- Alan Mackenzie (Munich, Germany) Email: aacm@muuc.dee; to decode, wherever there is a repeated letter (like "aa"), remove half of them (leaving, say, "a"). ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: marrying braket for ?: operator 2005-07-28 7:48 ` Alan Mackenzie @ 2005-07-28 20:06 ` Robert Marshall 2005-07-28 20:37 ` Kevin Rodgers 2005-07-28 22:04 ` Alan Mackenzie 0 siblings, 2 replies; 7+ messages in thread From: Robert Marshall @ 2005-07-28 20:06 UTC (permalink / raw) On Thu, 28 Jul 2005, Alan Mackenzie wrote: > Baloff <washdc@wash.edu> wrote on 28 Jul 2005 15:20:51 +1000: >> Hello > >> when I move my pointer to a braket, it highlight its marrying >> braket. but how can I get it to do the same with the ternary >> if-else operator (?:) I hope this is a good group for this question >> otherwise please point me. > > It's exactly the right group! > > There is no command which jumps from a ? to it's : or vice versa. > Maybe there should be one. Maybe somebody, somewhere, has > implemented one, and will jump in here with a URL pointing to the > source code. > > The thing is, though, how useful would this command be? Programmers > tend not to nest these conditional expressions very much. The > command would have to bound to a key sequence, something like C-c : > (that's "control-c colon"). By the time you've typed that in, you > could just as well have found the colon by interactive search by > typing C-s :. > And it's probably not straightforward (for either case), you might have (x > 4) ? weeble::kerplunk(funky::gibbon ? whoop : holler()) : foible::gibber::eugh(); Robert -- La grenouille songe..dans son château d'eau ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: marrying braket for ?: operator 2005-07-28 20:06 ` Robert Marshall @ 2005-07-28 20:37 ` Kevin Rodgers 2005-07-28 22:04 ` Alan Mackenzie 1 sibling, 0 replies; 7+ messages in thread From: Kevin Rodgers @ 2005-07-28 20:37 UTC (permalink / raw) Robert Marshall wrote: > And it's probably not straightforward (for either case), you might have > (x > 4) ? weeble::kerplunk(funky::gibbon ? whoop : holler()) : foible::gibber::eugh(); It would be a lot more straightforward if C-M-f (forward-sexp) and C-M-b (backward-sexp) would recognize things like foible::gibber::eugh() and weeble::kerplunk(funky::gibbon ? whoop : holler()) as single expressions to be skipped over. -- Kevin Rodgers ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: marrying braket for ?: operator 2005-07-28 20:06 ` Robert Marshall 2005-07-28 20:37 ` Kevin Rodgers @ 2005-07-28 22:04 ` Alan Mackenzie 2005-07-29 8:22 ` Baloff 1 sibling, 1 reply; 7+ messages in thread From: Alan Mackenzie @ 2005-07-28 22:04 UTC (permalink / raw) Robert Marshall <spam@chezmarshall.freeserve.co.uk> wrote on Thu, 28 Jul 2005 21:06:20 +0100: > On Thu, 28 Jul 2005, Alan Mackenzie wrote: >> Baloff <washdc@wash.edu> wrote on 28 Jul 2005 15:20:51 +1000: >>> Hello >>> when I move my pointer to a braket, it highlight its marrying >>> braket. but how can I get it to do the same with the ternary >>> if-else operator (?:) I hope this is a good group for this question >>> otherwise please point me. >> It's exactly the right group! >> There is no command which jumps from a ? to it's : or vice versa. >> Maybe there should be one. Maybe somebody, somewhere, has >> implemented one, and will jump in here with a URL pointing to the >> source code. >> The thing is, though, how useful would this command be? Programmers >> tend not to nest these conditional expressions very much. The >> command would have to bound to a key sequence, something like C-c : >> (that's "control-c colon"). By the time you've typed that in, you >> could just as well have found the colon by interactive search by >> typing C-s :. > And it's probably not straightforward (for either case), you might have > (x > 4) ? weeble::kerplunk(funky::gibbon ? whoop : holler()) : foible::gibber::eugh(); Believe me, compared with some of the stuff that's already in CC Mode, that's nothing. ;-) > Robert > -- > La grenouille songe..dans son château d'eau -- Alan Mackenzie (Munich, Germany) Email: aacm@muuc.dee; to decode, wherever there is a repeated letter (like "aa"), remove half of them (leaving, say, "a"). ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: marrying braket for ?: operator 2005-07-28 22:04 ` Alan Mackenzie @ 2005-07-29 8:22 ` Baloff 2005-07-31 12:20 ` Alan Mackenzie 0 siblings, 1 reply; 7+ messages in thread From: Baloff @ 2005-07-29 8:22 UTC (permalink / raw) Alan Mackenzie <acm@muc.de> writes: > Robert Marshall <spam@chezmarshall.freeserve.co.uk> wrote on Thu, 28 Jul > 2005 21:06:20 +0100: > > > On Thu, 28 Jul 2005, Alan Mackenzie wrote: > > >> Baloff <washdc@wash.edu> wrote on 28 Jul 2005 15:20:51 +1000: > >>> Hello > > >>> when I move my pointer to a braket, it highlight its marrying > >>> braket. but how can I get it to do the same with the ternary > >>> if-else operator (?:) I hope this is a good group for this question > >>> otherwise please point me. > > >> It's exactly the right group! > > >> There is no command which jumps from a ? to it's : or vice versa. > >> Maybe there should be one. Maybe somebody, somewhere, has > >> implemented one, and will jump in here with a URL pointing to the > >> source code. > > >> The thing is, though, how useful would this command be? Programmers > >> tend not to nest these conditional expressions very much. The > >> command would have to bound to a key sequence, something like C-c : > >> (that's "control-c colon"). By the time you've typed that in, you > >> could just as well have found the colon by interactive search by > >> typing C-s :. > > > > And it's probably not straightforward (for either case), you might have > > > (x > 4) ? weeble::kerplunk(funky::gibbon ? whoop : holler()) : foible::gibber::eugh(); > > Believe me, compared with some of the stuff that's already in CC Mode, > that's nothing. ;-) > > > Robert > > -- > > La grenouille songe..dans son château d'eau > > -- > Alan Mackenzie (Munich, Germany) > Email: aacm@muuc.dee; to decode, wherever there is a repeated letter > (like "aa"), remove half of them (leaving, say, "a"). thanks now that you know my .emacs and the lot how can I get enum colors { to go to a new line and indent like when I type say main(){ or for(...) { thanks ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: marrying braket for ?: operator 2005-07-29 8:22 ` Baloff @ 2005-07-31 12:20 ` Alan Mackenzie 0 siblings, 0 replies; 7+ messages in thread From: Alan Mackenzie @ 2005-07-31 12:20 UTC (permalink / raw) Baloff <washdc@wash.edu> wrote on 29 Jul 2005 18:22:26 +1000: [ .... ] > now that you know my .emacs and the lot how can I get > enum colors { to go to a new line and indent like when I type say > main(){ or for(...) { First remark: this works only when you've got "Auto Newline Mode" enabled, which you obviously already have. C-c C-a will toggle this mode. Second remark: The stuff here is documented in the CC Mode manual on the pages "Auto-newline Insertion" and "Hanging Braces". Third remark: Have a look at a C or C++ source file, and type C-c C-s on a few lines. This will show you the "syntactic context", i.e. CC Mode's syntactic analysis of the line. Put the { of "enum colors {" on its own line, and do C-c C-s there. It will tell you that this sort of brace is a "brace-list-open". In your CC Mode configuration, you need to change the setting `c-hanging-brace-alist'. While in a C/C++ buffer, do C-h C-v and have a look at the value of that variable. It will be something like this: ((brace-list-open) <=================== (block-open after) (defun-open after) (substatement-open after) (block-close . c-snug-do-while)) Each element of this list is itself a list. The first element (e.g. defun-open) gives the type of the brace, and the other elements (either "before", "after", both or none[*]), say where CC Mode is to insert the newlines for this sort of brace. [*] For advanced uses, a function can be specified here instead. For your brace-list-open element, I think you want "after", but you can change that yourself if need be. OK! Let's now go to your Lisp. Where you've got (c-add-style "mc394-style" '("cc-mode" (c-basic-offset . 3) ; In general, indent 3 spaces (c-hanging-braces-alist , you're creating a style called "mc394-style" which inherits from the style called "cc-mode". Since you're changing the style, you probably want to give it a new name, say "baloff-style", in a new file called baloff-style.el. So copy the file and change these lines to this: (c-add-style "baloff-style" '("cc-mode" (c-basic-offset . 3) ; In general, indent 3 spaces (c-hanging-braces-alist . A bit lower down, where you've got: (c-hanging-braces-alist ; These determine whether a newline appears before ; and/or after a brace in various situations. (brace-list-open) (block-open after) ; statement block open brace (defun-open after) ; brace that opens a function definition (substatement-open after); the brace that opens a substatement block (block-close . c-snug-do-while)) , change "(brace-list-open)" to "(brace-list-open after)". Load this new file (M-x load-file), Then from a C++ buffer, do C-c . (that's "control-C dot"), check your new style has been loaded, and set your buffer to this style. Check it does what you want, and if it doesn't, play around with it till it does. Then go through your .emacs, replacing all references to "mc394-style" with "baloff-style". Have fun! -- Alan Mackenzie (Munich, Germany) Email: aacm@muuc.dee; to decode, wherever there is a repeated letter (like "aa"), remove half of them (leaving, say, "a"). ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2005-07-31 12:20 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2005-07-28 5:20 marrying braket for ?: operator Baloff 2005-07-28 7:48 ` Alan Mackenzie 2005-07-28 20:06 ` Robert Marshall 2005-07-28 20:37 ` Kevin Rodgers 2005-07-28 22:04 ` Alan Mackenzie 2005-07-29 8:22 ` Baloff 2005-07-31 12:20 ` Alan Mackenzie
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).