* Re: Setting auto-indentation of braces
2009-02-10 10:10 Setting auto-indentation of braces Juha Nieminen
@ 2009-02-10 16:02 ` Tiago Pierezan Camargo
2009-02-10 16:46 ` Alan Mackenzie
` (2 subsequent siblings)
3 siblings, 0 replies; 26+ messages in thread
From: Tiago Pierezan Camargo @ 2009-02-10 16:02 UTC (permalink / raw)
To: help-gnu-emacs
On Tue, Feb 10, 2009 at 8:10 AM, Juha Nieminen <nospam@thanks.invalid> wrote:
> In the linux version of emacs, when I'm writing a C/C++/other {}-based
> language, when I write a { to start a new block, emacs automatically indents
> it.
> Which magic .emacs line turns this feature on?
http://www.gnu.org/software/emacs/manual/html_node/emacs/Electric-C.html#Electric-C
--
Tiago Pierezan Camargo
tcamargo at gmail dot com
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Setting auto-indentation of braces
2009-02-10 10:10 Setting auto-indentation of braces Juha Nieminen
2009-02-10 16:02 ` Tiago Pierezan Camargo
@ 2009-02-10 16:46 ` Alan Mackenzie
[not found] ` <mailman.328.1234283149.31690.help-gnu-emacs@gnu.org>
2009-02-16 9:50 ` Juha Nieminen
3 siblings, 0 replies; 26+ messages in thread
From: Alan Mackenzie @ 2009-02-10 16:46 UTC (permalink / raw)
To: Juha Nieminen; +Cc: help-gnu-emacs
Hi, Juha!
On Tue, Feb 10, 2009 at 12:10:07PM +0200, Juha Nieminen wrote:
> In the linux version of emacs, when I'm writing a C/C++/other
> {}-based language, when I write a { to start a new block, emacs
> automatically indents it.
> In the macosx version this autoindentation is off, and I can't figure
> out where to turn it on. I'm so accustomed to it, that it's annoying
> that it doesn't work...
How dare they! ;-) What's the betting they forgot to amend the manual
to match?
> Which magic .emacs line turns this feature on?
Try C-c C-l `c-toggle-electric-state' to begin with. If this works,
then all you need to do is switch this on in a hook function, something
like:
(defun jn-electric-on ()
(c-toggle-electric-state 1))
(add-hook 'c-mode-common-hook 'jn-electric-on)
If this doesn't work, please send a dump of your CC Mode configuration,
created by C-c C-b. Either send it off to bug-cc-mode@gnu.org, or
change the To: address, or put and caste it to a different mail client,
or whatever.
The documentation for this is the CC Mode manual, which should have been
distributed together with your Emacs.
--
Alan Mackenzie (Nuremberg, Germany).
^ permalink raw reply [flat|nested] 26+ messages in thread
[parent not found: <mailman.328.1234283149.31690.help-gnu-emacs@gnu.org>]
* Re: Setting auto-indentation of braces
2009-02-10 10:10 Setting auto-indentation of braces Juha Nieminen
` (2 preceding siblings ...)
[not found] ` <mailman.328.1234283149.31690.help-gnu-emacs@gnu.org>
@ 2009-02-16 9:50 ` Juha Nieminen
2009-02-18 8:44 ` Juha Nieminen
` (3 more replies)
3 siblings, 4 replies; 26+ messages in thread
From: Juha Nieminen @ 2009-02-16 9:50 UTC (permalink / raw)
To: help-gnu-emacs
Juha Nieminen kirjoitti:
> In the macosx version this autoindentation is off, and I can't figure
> out where to turn it on. I'm so accustomed to it, that it's annoying
> that it doesn't work...
Oh, man... I'm such an IDIOT! *bangs head on wall*
You see, Macs have this really weird keyboard configuration for the
Finnish keyboard (which I'm using) which is completely different from
the PC configuration which I'm accustomed to from well over 10 years.
In the PC to get the curly braces you press AltGr+7 and AltGr+0, but
on the Mac you have to press Alt+Shift+8 and Alt+Shift+9. Needless
to say that this is really awkward to use, and I'm not accustomed to it.
Thus I searched for a way in MacOS X to reconfigure this, and I
couldn't find any way. (Maybe there is, but I just couldn't find it. So
much for the famous "easy to use" OS...) So instead I went and tried
to remap these keys in my .emacs instead. I suppose you already
guess the reason why those braces were not being auto-indented...
The thing is, no matter how much I tried to search info on how to
do it, I couldn't find a way to remap keys in .emacs. Or more precisely,
I couldn't find a way to make a given key combination be equivalent
to pressing some other key. So I invented this really ugly hack to get
around the problem:
(defun insert-string(s)
(if (re-search-forward "" nil t)
(replace-match s)))
(defun insert-open-curly() (interactive) (insert-string "{"))
(global-set-key "\M-7" 'insert-open-curly)
Yes, as said, this is a really horrible hack, but with my limited
knowledge of emacs it was the only thing I could come up with.
I couldn't find any other way of "remapping" eg. "\M-7" to the curly
brace. No wonder emacs is not auto-indenting the brace because
I'm completely bypassing the logic behind it.
And indeed, if I type the curly brace with Alt+Shift+8 then it gets
properly auto-indented.
I suppose my question is: What is the proper way of remapping
keys, which will not bypass any auto-indenting routines?
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Setting auto-indentation of braces
2009-02-16 9:50 ` Juha Nieminen
@ 2009-02-18 8:44 ` Juha Nieminen
2009-02-18 19:00 ` Peter Dyballa
[not found] ` <mailman.1097.1234983644.31690.help-gnu-emacs@gnu.org>
2009-02-18 12:57 ` tyler
` (2 subsequent siblings)
3 siblings, 2 replies; 26+ messages in thread
From: Juha Nieminen @ 2009-02-18 8:44 UTC (permalink / raw)
To: help-gnu-emacs
Juha Nieminen kirjoitti:
> I suppose my question is: What is the proper way of remapping
> keys, which will not bypass any auto-indenting routines?
Does this mean there's no way in emacs to remap keys (so that a key
combination, such as "\M-7", is made equivalent to pressing some other
key or key combination, such as "{")?
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Setting auto-indentation of braces
2009-02-18 8:44 ` Juha Nieminen
@ 2009-02-18 19:00 ` Peter Dyballa
2009-02-19 4:07 ` Kevin Rodgers
[not found] ` <mailman.1146.1235016448.31690.help-gnu-emacs@gnu.org>
[not found] ` <mailman.1097.1234983644.31690.help-gnu-emacs@gnu.org>
1 sibling, 2 replies; 26+ messages in thread
From: Peter Dyballa @ 2009-02-18 19:00 UTC (permalink / raw)
To: Juha Nieminen; +Cc: help-gnu-emacs
Am 18.02.2009 um 09:44 schrieb Juha Nieminen:
> Does this mean there's no way in emacs to remap keys (so that a
> key combination, such as "\M-7", is made equivalent to pressing
> some other key or key combination, such as "{")?
Maybe you just need to understand that a minor-mode keymap overrides
a global-mode keymap when in some buffer this minor-mode is
active ... (meaning: apply your changes to the keymap owned by that C
mode)
--
Greetings
Pete
When you meet a master swordsman,
show him your sword.
When you meet a man who is not a poet,
do not show him your poem.
– Rinzai, ninth century Zen master
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Setting auto-indentation of braces
2009-02-18 19:00 ` Peter Dyballa
@ 2009-02-19 4:07 ` Kevin Rodgers
[not found] ` <mailman.1146.1235016448.31690.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 26+ messages in thread
From: Kevin Rodgers @ 2009-02-19 4:07 UTC (permalink / raw)
To: help-gnu-emacs
Peter Dyballa wrote:
>
> Am 18.02.2009 um 09:44 schrieb Juha Nieminen:
>
>> Does this mean there's no way in emacs to remap keys (so that a key
>> combination, such as "\M-7", is made equivalent to pressing some other
>> key or key combination, such as "{")?
One way is to define it as a macro: (global-set-key (kbd "M-7") "{")
or (local-set-key (kbd "M-7") "{") within an appropriate hook.
> Maybe you just need to understand that a minor-mode keymap overrides a
> global-mode keymap when in some buffer this minor-mode is active ...
> (meaning: apply your changes to the keymap owned by that C mode)
I think you mean major-mode keymap there, although minor-mode keymaps
are relevant as well. For a precise explanation, see the and the Local
Keymaps node of the Emacs manual and the Searching [the Active] Keymaps
node of the Emacs Lisp manual.
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 26+ messages in thread
[parent not found: <mailman.1146.1235016448.31690.help-gnu-emacs@gnu.org>]
* Re: Setting auto-indentation of braces
[not found] ` <mailman.1146.1235016448.31690.help-gnu-emacs@gnu.org>
@ 2009-02-23 9:47 ` Juha Nieminen
2009-02-23 11:24 ` Teemu Likonen
` (3 more replies)
0 siblings, 4 replies; 26+ messages in thread
From: Juha Nieminen @ 2009-02-23 9:47 UTC (permalink / raw)
To: help-gnu-emacs
Kevin Rodgers kirjoitti:
> (global-set-key (kbd "M-7") "{")
(global-set-key "M-7" "{") seems to work as well.
This is exactly what I was looking for. I didn't know you could give
directly a string to global-set-key, rather than a command (as I
mentioned, my knowledge of elisp is next to nil).
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Setting auto-indentation of braces
2009-02-23 9:47 ` Juha Nieminen
@ 2009-02-23 11:24 ` Teemu Likonen
2009-02-24 4:56 ` Kevin Rodgers
` (2 subsequent siblings)
3 siblings, 0 replies; 26+ messages in thread
From: Teemu Likonen @ 2009-02-23 11:24 UTC (permalink / raw)
To: help-gnu-emacs
On 2009-02-23 11:47 (+0200), Juha Nieminen wrote:
> (as I mentioned, my knowledge of elisp is next to nil).
(when (or (not knowledge-of-elisp)
(next-to knowledge-of-elisp nil))
(info "(eintr) Top"))
:-)
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Setting auto-indentation of braces
2009-02-23 9:47 ` Juha Nieminen
2009-02-23 11:24 ` Teemu Likonen
@ 2009-02-24 4:56 ` Kevin Rodgers
[not found] ` <mailman.1617.1235451361.31690.help-gnu-emacs@gnu.org>
2009-02-25 16:14 ` Juha Nieminen
3 siblings, 0 replies; 26+ messages in thread
From: Kevin Rodgers @ 2009-02-24 4:56 UTC (permalink / raw)
To: help-gnu-emacs
Juha Nieminen wrote:
> Kevin Rodgers kirjoitti:
>> (global-set-key (kbd "M-7") "{")
>
> (global-set-key "M-7" "{") seems to work as well.
Well, it shouldn't: that binds a 3-character sequence (M, dash, 7) to
left-brace.
> This is exactly what I was looking for. I didn't know you could give
> directly a string to global-set-key, rather than a command (as I
> mentioned, my knowledge of elisp is next to nil).
You can bind anything that satisfies commandp, whose doc string says:
Interactively callable functions include strings and vectors (treated
as keyboard macros), lambda-expressions that contain a top-level call
to `interactive', autoload definitions made by `autoload' with non-nil
fourth argument, and some of the built-in functions of Lisp.
Also, a symbol satisfies `commandp' if its function definition does so.
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 26+ messages in thread
[parent not found: <mailman.1617.1235451361.31690.help-gnu-emacs@gnu.org>]
* Re: Setting auto-indentation of braces
2009-02-23 9:47 ` Juha Nieminen
` (2 preceding siblings ...)
[not found] ` <mailman.1617.1235451361.31690.help-gnu-emacs@gnu.org>
@ 2009-02-25 16:14 ` Juha Nieminen
2009-03-04 23:59 ` Juha Nieminen
` (2 more replies)
3 siblings, 3 replies; 26+ messages in thread
From: Juha Nieminen @ 2009-02-25 16:14 UTC (permalink / raw)
To: help-gnu-emacs
Juha Nieminen wrote:
> Kevin Rodgers kirjoitti:
>> (global-set-key (kbd "M-7") "{")
>
> (global-set-key "M-7" "{") seems to work as well.
>
> This is exactly what I was looking for. I didn't know you could give
> directly a string to global-set-key, rather than a command (as I
> mentioned, my knowledge of elisp is next to nil).
New problem: When I do that, and then press ctrl-s to start a search
and press the key combination in question, rather than inserting { in
the search area at the bottom of the window, it instead cancels the
search and inserts the { in the current buffer, as if I hadn't started a
search at all.
Why is it doing that?
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Setting auto-indentation of braces
2009-02-25 16:14 ` Juha Nieminen
@ 2009-03-04 23:59 ` Juha Nieminen
2009-03-05 9:20 ` Nikolaj Schumacher
[not found] ` <mailman.2415.1236244816.31690.help-gnu-emacs@gnu.org>
2009-03-12 5:15 ` Kevin Rodgers
[not found] ` <mailman.2991.1237105197.31690.help-gnu-emacs@gnu.org>
2 siblings, 2 replies; 26+ messages in thread
From: Juha Nieminen @ 2009-03-04 23:59 UTC (permalink / raw)
To: help-gnu-emacs
Juha Nieminen wrote:
> Juha Nieminen wrote:
>> Kevin Rodgers kirjoitti:
>>> (global-set-key (kbd "M-7") "{")
>> (global-set-key "M-7" "{") seems to work as well.
>>
>> This is exactly what I was looking for. I didn't know you could give
>> directly a string to global-set-key, rather than a command (as I
>> mentioned, my knowledge of elisp is next to nil).
>
> New problem: When I do that, and then press ctrl-s to start a search
> and press the key combination in question, rather than inserting { in
> the search area at the bottom of the window, it instead cancels the
> search and inserts the { in the current buffer, as if I hadn't started a
> search at all.
>
> Why is it doing that?
Seemingly nobody knows?
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Setting auto-indentation of braces
2009-03-04 23:59 ` Juha Nieminen
@ 2009-03-05 9:20 ` Nikolaj Schumacher
[not found] ` <mailman.2415.1236244816.31690.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 26+ messages in thread
From: Nikolaj Schumacher @ 2009-03-05 9:20 UTC (permalink / raw)
To: help-gnu-emacs
Juha Nieminen <nospam@thanks.invalid> wrote: > Juha Nieminen
wrote: >> Juha Nieminen wrote: >>> Kevin Rodgers kirjoitti: >>>>
(global-set-key (kbd "M-7") "{") >>> (global-set-key "M-7" "{")
seems to work as well. >>> >> New problem: When I do that, and
then press ctrl-s to start a search >> and press the key
combination in question, rather than inserting { in >> the search
area at the bottom of the window, it instead cancels the >> search
and inserts the { in the current buffer, as if I hadn't started a
>> search at all. >> >> Why is it doing that?
I think I can tell you why. isearch is a mode, and it terminates
itself automatically on every command it doesn't recognize.
Assigning keys that way is the same as using a keyboard macro,
which inserts an additional command in the queue, causing isearch
to exit.
Here's my work-around:
(defun do-what-backspace-does () (interactive) (call-interactively
(key-binding (kbd "<backspace>")))) (global-set-key "\C-h"
'do-what-backspace-does)
I think it should work in your case, too. regards, Nikolaj
Schumacher
PS: If you'd use a real email address (even if you don't read it),
you'd save me the trouble of getting my emails returned to me as
undeliverable. Thanks.
^ permalink raw reply [flat|nested] 26+ messages in thread
[parent not found: <mailman.2415.1236244816.31690.help-gnu-emacs@gnu.org>]
* Re: Setting auto-indentation of braces
2009-02-25 16:14 ` Juha Nieminen
2009-03-04 23:59 ` Juha Nieminen
@ 2009-03-12 5:15 ` Kevin Rodgers
[not found] ` <mailman.2991.1237105197.31690.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 26+ messages in thread
From: Kevin Rodgers @ 2009-03-12 5:15 UTC (permalink / raw)
To: help-gnu-emacs
Juha Nieminen wrote:
> Juha Nieminen wrote:
>> Kevin Rodgers kirjoitti:
>>> (global-set-key (kbd "M-7") "{")
>> (global-set-key "M-7" "{") seems to work as well.
>>
>> This is exactly what I was looking for. I didn't know you could give
>> directly a string to global-set-key, rather than a command (as I
>> mentioned, my knowledge of elisp is next to nil).
>
> New problem: When I do that, and then press ctrl-s to start a search
> and press the key combination in question, rather than inserting { in
> the search area at the bottom of the window, it instead cancels the
> search and inserts the { in the current buffer, as if I hadn't started a
> search at all.
>
> Why is it doing that?
Because when you've typed C-s, the global keymap is not the highest
precedence keymap that has bound M-7: isearch-mode-map is, and it
binds all escape sequences (to which Meta-prefixed characters are
translated) to isearch-other-meta-char.
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 26+ messages in thread
[parent not found: <mailman.2991.1237105197.31690.help-gnu-emacs@gnu.org>]
[parent not found: <mailman.1097.1234983644.31690.help-gnu-emacs@gnu.org>]
* Re: Setting auto-indentation of braces
[not found] ` <mailman.1097.1234983644.31690.help-gnu-emacs@gnu.org>
@ 2009-02-18 23:43 ` Juha Nieminen
2009-02-19 9:40 ` Peter Dyballa
0 siblings, 1 reply; 26+ messages in thread
From: Juha Nieminen @ 2009-02-18 23:43 UTC (permalink / raw)
To: help-gnu-emacs
Peter Dyballa wrote:
>
> Am 18.02.2009 um 09:44 schrieb Juha Nieminen:
>
>> Does this mean there's no way in emacs to remap keys (so that a key
>> combination, such as "\M-7", is made equivalent to pressing some other
>> key or key combination, such as "{")?
>
> Maybe you just need to understand that a minor-mode keymap overrides a
> global-mode keymap when in some buffer this minor-mode is active ...
> (meaning: apply your changes to the keymap owned by that C mode)
Apply? How? That's exactly what I'm asking.
I don't know elisp. I don't know how to remap keys in emacs,
regardless of the mode.
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Setting auto-indentation of braces
2009-02-16 9:50 ` Juha Nieminen
2009-02-18 8:44 ` Juha Nieminen
@ 2009-02-18 12:57 ` tyler
[not found] ` <mailman.1065.1234961877.31690.help-gnu-emacs@gnu.org>
2009-02-19 11:31 ` Miles Bader
3 siblings, 0 replies; 26+ messages in thread
From: tyler @ 2009-02-18 12:57 UTC (permalink / raw)
To: help-gnu-emacs
Juha Nieminen <nospam@thanks.invalid> writes:
> Juha Nieminen kirjoitti:
>> In the macosx version this autoindentation is off, and I can't
>> figure out where to turn it on. I'm so accustomed to it, that it's
>> annoying that it doesn't work...
>
>
> (defun insert-string(s)
> (if (re-search-forward "" nil t)
> (replace-match s)))
> (defun insert-open-curly() (interactive) (insert-string "{"))
> (global-set-key "\M-7" 'insert-open-curly)
>
> Yes, as said, this is a really horrible hack, but with my limited
> knowledge of emacs it was the only thing I could come up with.
> I couldn't find any other way of "remapping" eg. "\M-7" to the curly
> brace. No wonder emacs is not auto-indenting the brace because
> I'm completely bypassing the logic behind it.
You have remapped M-7 to (insert-string "{"). If you open a file in
c-mode, and then enter C-h k { (no spaces), you'll see that the '{' key
is actually bound to c-electric-brace, not self-insert. So that's what
you should be targeting with your remapping.
Tyler
--
I'm Tyler Smith and I approve of this email.
^ permalink raw reply [flat|nested] 26+ messages in thread
[parent not found: <mailman.1065.1234961877.31690.help-gnu-emacs@gnu.org>]
* Re: Setting auto-indentation of braces
2009-02-16 9:50 ` Juha Nieminen
` (2 preceding siblings ...)
[not found] ` <mailman.1065.1234961877.31690.help-gnu-emacs@gnu.org>
@ 2009-02-19 11:31 ` Miles Bader
3 siblings, 0 replies; 26+ messages in thread
From: Miles Bader @ 2009-02-19 11:31 UTC (permalink / raw)
To: help-gnu-emacs
What you want to do is just ask emacs "What command is the { key bound to",
and then bind your new key to the same command.
To see what the { key is bound to, you can use the "describe-key-briefly"
command, normally bound to "C-h c" (of course you should do it while in the
C file's buffer):
C-h c {
(I see in my emacs, it's bound to "c-electric-brace" in c-mode)
Emacs has a lot of useful commands for getting information, most of
which start with "C-h" (do C-h C-h to see more).
-Miles
--
I'm beginning to think that life is just one long Yoko Ono album; no rhyme
or reason, just a lot of incoherent shrieks and then it's over. --Ian Wolff
^ permalink raw reply [flat|nested] 26+ messages in thread