* Tabs and Spaces
@ 2009-05-25 10:48 Chris Gordon-Smith
2009-05-25 11:48 ` Pascal J. Bourguignon
` (5 more replies)
0 siblings, 6 replies; 22+ messages in thread
From: Chris Gordon-Smith @ 2009-05-25 10:48 UTC (permalink / raw)
To: help-gnu-emacs
Hello All
I have recenly started using emacs for programming, after years using
KDevelop. One problem I have is indenting code. I have my own indentation
style. and ideally I would like to setup emacs to support it automatically.
However, in the short term I'll settle for having emacs convert a TAB
keypress into the correct number of spaces to fill whitespace up to the
next tabstop.
At the moment I have
(global-set-key (kbd "TAB") 'self-insert-command)
in my .emacs to force insertion of a tab, but I have to keep invoking
untabify manually (otherwise my code looks misaligned when I upload it to
Google Code).
Can anyone help.
Chris Gordon-Smith
www.simsoup.info
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Tabs and Spaces
2009-05-25 10:48 Tabs and Spaces Chris Gordon-Smith
@ 2009-05-25 11:48 ` Pascal J. Bourguignon
2009-05-25 12:17 ` Chris Gordon-Smith
2009-05-25 16:15 ` B Smith-Mannschott
` (4 subsequent siblings)
5 siblings, 1 reply; 22+ messages in thread
From: Pascal J. Bourguignon @ 2009-05-25 11:48 UTC (permalink / raw)
To: help-gnu-emacs
use.address@my.homepage.invalid (Chris Gordon-Smith) writes:
> Hello All
>
> I have recenly started using emacs for programming, after years using
> KDevelop. One problem I have is indenting code. I have my own indentation
> style. and ideally I would like to setup emacs to support it automatically.
> However, in the short term I'll settle for having emacs convert a TAB
> keypress into the correct number of spaces to fill whitespace up to the
> next tabstop.
>
> At the moment I have
>
> (global-set-key (kbd "TAB") 'self-insert-command)
>
> in my .emacs to force insertion of a tab, but I have to keep invoking
> untabify manually (otherwise my code looks misaligned when I upload it to
> Google Code).
>
> Can anyone help.
You shouldn't insert TAB, this is very bad. At the very least, you
may compute the number of spaces you need to insert and insert them
rather.
But depending on the language you use, a different mode will be used
to edit your source and each mode may provide its own indenting rules.
In the case of Lisp, you may add a indent-function property to the
plist of the operator name.
In the case of C, you may customize the variable: c-offsets-alist. See
also: c-style-alist ; perhaps there's already a style defined that
you'll like.
--
__Pascal Bourguignon__
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Tabs and Spaces
2009-05-25 11:48 ` Pascal J. Bourguignon
@ 2009-05-25 12:17 ` Chris Gordon-Smith
2009-05-25 13:48 ` Pascal J. Bourguignon
0 siblings, 1 reply; 22+ messages in thread
From: Chris Gordon-Smith @ 2009-05-25 12:17 UTC (permalink / raw)
To: help-gnu-emacs
Pascal J. Bourguignon <pjb@informatimago.com> wrote:
> use.address@my.homepage.invalid (Chris Gordon-Smith) writes:
>
>> Hello All
>>
>> I have recenly started using emacs for programming, after years using
>> KDevelop. One problem I have is indenting code. I have my own indentation
>> style. and ideally I would like to setup emacs to support it automatically.
>> However, in the short term I'll settle for having emacs convert a TAB
>> keypress into the correct number of spaces to fill whitespace up to the
>> next tabstop.
>>
>> At the moment I have
>>
>> (global-set-key (kbd "TAB") 'self-insert-command)
>>
>> in my .emacs to force insertion of a tab, but I have to keep invoking
>> untabify manually (otherwise my code looks misaligned when I upload it to
>> Google Code).
>>
>> Can anyone help.
>
> You shouldn't insert TAB, this is very bad. At the very least, you
> may compute the number of spaces you need to insert and insert them
> rather.
Yes, that's what I would like to do. Can you suggest how to do this. Do I
need to put something in my .emacs file. What would it look like?
>
> But depending on the language you use, a different mode will be used
> to edit your source and each mode may provide its own indenting rules.
>
> In the case of Lisp, you may add a indent-function property to the
> plist of the operator name.
>
> In the case of C, you may customize the variable: c-offsets-alist. See
> also: c-style-alist ; perhaps there's already a style defined that
> you'll like.
>
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Tabs and Spaces
2009-05-25 12:17 ` Chris Gordon-Smith
@ 2009-05-25 13:48 ` Pascal J. Bourguignon
2009-05-25 14:58 ` Chris Gordon-Smith
0 siblings, 1 reply; 22+ messages in thread
From: Pascal J. Bourguignon @ 2009-05-25 13:48 UTC (permalink / raw)
To: help-gnu-emacs
use.address@my.homepage.invalid (Chris Gordon-Smith) writes:
> Pascal J. Bourguignon <pjb@informatimago.com> wrote:
>> use.address@my.homepage.invalid (Chris Gordon-Smith) writes:
>>
>>> Hello All
>>>
>>> I have recenly started using emacs for programming, after years using
>>> KDevelop. One problem I have is indenting code. I have my own indentation
>>> style. and ideally I would like to setup emacs to support it automatically.
>>> However, in the short term I'll settle for having emacs convert a TAB
>>> keypress into the correct number of spaces to fill whitespace up to the
>>> next tabstop.
>>>
>>> At the moment I have
>>>
>>> (global-set-key (kbd "TAB") 'self-insert-command)
>>>
>>> in my .emacs to force insertion of a tab, but I have to keep invoking
>>> untabify manually (otherwise my code looks misaligned when I upload it to
>>> Google Code).
>>>
>>> Can anyone help.
>>
>> You shouldn't insert TAB, this is very bad. At the very least, you
>> may compute the number of spaces you need to insert and insert them
>> rather.
> Yes, that's what I would like to do. Can you suggest how to do this. Do I
> need to put something in my .emacs file. What would it look like?
>
>>
>> But depending on the language you use, a different mode will be used
>> to edit your source and each mode may provide its own indenting rules.
>>
>> In the case of Lisp, you may add a indent-function property to the
>> plist of the operator name.
>>
>> In the case of C, you may customize the variable: c-offsets-alist. See
>> also: c-style-alist ; perhaps there's already a style defined that
>> you'll like.
In my post, there was a subliminal question, but it didn't reach your
consciousness, I'm sorry. Here it is:
What programming language do you use?
Depending on the answer you give, you may well have nothing to program.
Otherwise, you could do something like this:
(defconst +space+ 32 "ASCII code for the space character")
(defun my-language/indent-line ()
(interactive)
(let ((where (let ((m (make-marker))) (set-marker m (point)) m))
(indent (my-language/get-indent-from-some-parsing-around (point))))
(beginning-of-line)
(looking-at "^[ \t]*")
(delete-region (beginning-of-line) (match-end))
(goto-char (beginning-of-line))
(insert (make-string indent +space+))
(goto-char where)
(set-marker where nil)))
(local-set-key (kbd "TAB") 'my-language/indent-line)
Of course, all the difficulty (or simplicity, depends on your language)
is in implementing my-language/get-indent-from-some-parsing-around.
--
__Pascal Bourguignon__
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Tabs and Spaces
2009-05-25 13:48 ` Pascal J. Bourguignon
@ 2009-05-25 14:58 ` Chris Gordon-Smith
2009-05-25 15:10 ` Teemu Likonen
2009-05-25 15:14 ` Pascal J. Bourguignon
0 siblings, 2 replies; 22+ messages in thread
From: Chris Gordon-Smith @ 2009-05-25 14:58 UTC (permalink / raw)
To: help-gnu-emacs
Pascal J. Bourguignon <pjb@informatimago.com> wrote:
> use.address@my.homepage.invalid (Chris Gordon-Smith) writes:
>
>> Pascal J. Bourguignon <pjb@informatimago.com> wrote:
>>> use.address@my.homepage.invalid (Chris Gordon-Smith) writes:
>>>
>>>> Hello All
>>>>
>>>> I have recenly started using emacs for programming, after years using
>>>> KDevelop. One problem I have is indenting code. I have my own indentation
>>>> style. and ideally I would like to setup emacs to support it automatically.
>>>> However, in the short term I'll settle for having emacs convert a TAB
>>>> keypress into the correct number of spaces to fill whitespace up to the
>>>> next tabstop.
>>>>
>>>> At the moment I have
>>>>
>>>> (global-set-key (kbd "TAB") 'self-insert-command)
>>>>
>>>> in my .emacs to force insertion of a tab, but I have to keep invoking
>>>> untabify manually (otherwise my code looks misaligned when I upload it to
>>>> Google Code).
>>>>
>>>> Can anyone help.
>>>
>>> You shouldn't insert TAB, this is very bad. At the very least, you
>>> may compute the number of spaces you need to insert and insert them
>>> rather.
>> Yes, that's what I would like to do. Can you suggest how to do this. Do I
>> need to put something in my .emacs file. What would it look like?
>>
>>>
>>> But depending on the language you use, a different mode will be used
>>> to edit your source and each mode may provide its own indenting rules.
>>>
>>> In the case of Lisp, you may add a indent-function property to the
>>> plist of the operator name.
>>>
>>> In the case of C, you may customize the variable: c-offsets-alist. See
>>> also: c-style-alist ; perhaps there's already a style defined that
>>> you'll like.
>
>
> In my post, there was a subliminal question, but it didn't reach your
> consciousness, I'm sorry. Here it is:
It wasn't really a question, and the fact that you had mentioned that the
solution to the problem might be language dependent did register with me.
I think its a pity that you chose to answer in what appears to be a rather
rude manner.
>
> What programming language do you use?
C++. But I had already established before my original post that the
standard emacs indenting would not suit me. Perhaps I should have mentioned
this.
>
> Depending on the answer you give, you may well have nothing to program.
> Otherwise, you could do something like this:
>
> (defconst +space+ 32 "ASCII code for the space character")
>
> (defun my-language/indent-line ()
> (interactive)
> (let ((where (let ((m (make-marker))) (set-marker m (point)) m))
> (indent (my-language/get-indent-from-some-parsing-around (point))))
> (beginning-of-line)
> (looking-at "^[ \t]*")
> (delete-region (beginning-of-line) (match-end))
> (goto-char (beginning-of-line))
> (insert (make-string indent +space+))
> (goto-char where)
> (set-marker where nil)))
>
>
> (local-set-key (kbd "TAB") 'my-language/indent-line)
>
>
> Of course, all the difficulty (or simplicity, depends on your language)
> is in implementing my-language/get-indent-from-some-parsing-around.
>
>
Thanks for this.
I'll need to read it and understand it before I use it, but it looks like a
good starting point.
Chris Gordon-Smith
www.simsoup.info
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Tabs and Spaces
2009-05-25 14:58 ` Chris Gordon-Smith
@ 2009-05-25 15:10 ` Teemu Likonen
2009-05-25 15:58 ` Chris Gordon-Smith
2009-05-25 15:14 ` Pascal J. Bourguignon
1 sibling, 1 reply; 22+ messages in thread
From: Teemu Likonen @ 2009-05-25 15:10 UTC (permalink / raw)
To: help-gnu-emacs
On 2009-05-25 14:58 (UTC), Chris Gordon-Smith wrote:
> C++. But I had already established before my original post that the
> standard emacs indenting would not suit me. Perhaps I should have
> mentioned this.
Fortunately C++ indentation is very much configurable. There are several
predefined styles which you can change with "C-c ." (c-set-style)
command. If none of them suit you you can create your own. For more info
see the CC Mode info node
C-h i d m CC Mode RET
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Tabs and Spaces
2009-05-25 14:58 ` Chris Gordon-Smith
2009-05-25 15:10 ` Teemu Likonen
@ 2009-05-25 15:14 ` Pascal J. Bourguignon
2009-05-25 15:36 ` Richard Riley
1 sibling, 1 reply; 22+ messages in thread
From: Pascal J. Bourguignon @ 2009-05-25 15:14 UTC (permalink / raw)
To: help-gnu-emacs
use.address@my.homepage.invalid (Chris Gordon-Smith) writes:
> Pascal J. Bourguignon <pjb@informatimago.com> wrote:
>> use.address@my.homepage.invalid (Chris Gordon-Smith) writes:
>>
>>> Pascal J. Bourguignon <pjb@informatimago.com> wrote:
>>>> use.address@my.homepage.invalid (Chris Gordon-Smith) writes:
>>>>
>>>>> Hello All
>>>>>
>>>>> I have recenly started using emacs for programming, after years using
>>>>> KDevelop. One problem I have is indenting code. I have my own indentation
>>>>> style. and ideally I would like to setup emacs to support it automatically.
>>>>> However, in the short term I'll settle for having emacs convert a TAB
>>>>> keypress into the correct number of spaces to fill whitespace up to the
>>>>> next tabstop.
>>>>>
>>>>> At the moment I have
>>>>>
>>>>> (global-set-key (kbd "TAB") 'self-insert-command)
>>>>>
>>>>> in my .emacs to force insertion of a tab, but I have to keep invoking
>>>>> untabify manually (otherwise my code looks misaligned when I upload it to
>>>>> Google Code).
>>>>>
>>>>> Can anyone help.
>>>>
>>>> You shouldn't insert TAB, this is very bad. At the very least, you
>>>> may compute the number of spaces you need to insert and insert them
>>>> rather.
>>> Yes, that's what I would like to do. Can you suggest how to do this. Do I
>>> need to put something in my .emacs file. What would it look like?
>>>
>>>>
>>>> But depending on the language you use, a different mode will be used
>>>> to edit your source and each mode may provide its own indenting rules.
>>>>
>>>> In the case of Lisp, you may add a indent-function property to the
>>>> plist of the operator name.
>>>>
>>>> In the case of C, you may customize the variable: c-offsets-alist. See
>>>> also: c-style-alist ; perhaps there's already a style defined that
>>>> you'll like.
>>
>>
>> In my post, there was a subliminal question, but it didn't reach your
>> consciousness, I'm sorry. Here it is:
>
> It wasn't really a question, and the fact that you had mentioned that the
> solution to the problem might be language dependent did register with me.
>
> I think its a pity that you chose to answer in what appears to be a rather
> rude manner.
That wasn't intended. Sorry again.
>> What programming language do you use?
>
> C++. But I had already established before my original post that the
> standard emacs indenting would not suit me. Perhaps I should have mentioned
> this.
c++-mode is derived from c-mode, you can configure c-offsets-alist and
possibly define your own c-style in c-style-alist.
The point here is that almost all the syntactic elements of C/C++ are
already taken into account by the C indenting functions, so you only
need to specify the indenting you want, and let the existing machinery
do the work for you.
>> Depending on the answer you give, you may well have nothing to program.
>> Otherwise, you could do something like this:
>>
>> (defconst +space+ 32 "ASCII code for the space character")
>>
>> (defun my-language/indent-line ()
>> (interactive)
>> (let ((where (let ((m (make-marker))) (set-marker m (point)) m))
>> (indent (my-language/get-indent-from-some-parsing-around (point))))
>> (beginning-of-line)
>> (looking-at "^[ \t]*")
>> (delete-region (beginning-of-line) (match-end))
>> (goto-char (beginning-of-line))
>> (insert (make-string indent +space+))
>> (goto-char where)
>> (set-marker where nil)))
>>
>>
>> (local-set-key (kbd "TAB") 'my-language/indent-line)
>>
>>
>> Of course, all the difficulty (or simplicity, depends on your language)
>> is in implementing my-language/get-indent-from-some-parsing-around.
>>
>>
>
> Thanks for this.
> I'll need to read it and understand it before I use it, but it looks like a
> good starting point.
Well, C++ is quite difficult to parse, so you should really first try
to configure the existing emacs C indentation feature.
However, if you want to write your own parser, you may use the
bovinator from cedet: http://cedet.sourceforge.net/
http://cedet.sourceforge.net/semantic.shtml
--
__Pascal Bourguignon__
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Tabs and Spaces
2009-05-25 15:14 ` Pascal J. Bourguignon
@ 2009-05-25 15:36 ` Richard Riley
2009-05-25 16:10 ` Pascal J. Bourguignon
0 siblings, 1 reply; 22+ messages in thread
From: Richard Riley @ 2009-05-25 15:36 UTC (permalink / raw)
To: help-gnu-emacs
pjb@informatimago.com (Pascal J. Bourguignon) writes:
> use.address@my.homepage.invalid (Chris Gordon-Smith) writes:
>
>> Pascal J. Bourguignon <pjb@informatimago.com> wrote:
>>> use.address@my.homepage.invalid (Chris Gordon-Smith) writes:
>>>
>>>> Pascal J. Bourguignon <pjb@informatimago.com> wrote:
>>>>> use.address@my.homepage.invalid (Chris Gordon-Smith) writes:
>>>>>
>>>>>> Hello All
>>>>>>
>>>>>> I have recenly started using emacs for programming, after years using
>>>>>> KDevelop. One problem I have is indenting code. I have my own indentation
>>>>>> style. and ideally I would like to setup emacs to support it automatically.
>>>>>> However, in the short term I'll settle for having emacs convert a TAB
>>>>>> keypress into the correct number of spaces to fill whitespace up to the
>>>>>> next tabstop.
>>>>>>
>>>>>> At the moment I have
>>>>>>
>>>>>> (global-set-key (kbd "TAB") 'self-insert-command)
>>>>>>
>>>>>> in my .emacs to force insertion of a tab, but I have to keep invoking
>>>>>> untabify manually (otherwise my code looks misaligned when I upload it to
>>>>>> Google Code).
>>>>>>
>>>>>> Can anyone help.
>>>>>
>>>>> You shouldn't insert TAB, this is very bad. At the very least, you
>>>>> may compute the number of spaces you need to insert and insert them
>>>>> rather.
>>>> Yes, that's what I would like to do. Can you suggest how to do this. Do I
>>>> need to put something in my .emacs file. What would it look like?
>>>>
>>>>>
>>>>> But depending on the language you use, a different mode will be used
>>>>> to edit your source and each mode may provide its own indenting rules.
>>>>>
>>>>> In the case of Lisp, you may add a indent-function property to the
>>>>> plist of the operator name.
>>>>>
>>>>> In the case of C, you may customize the variable: c-offsets-alist. See
>>>>> also: c-style-alist ; perhaps there's already a style defined that
>>>>> you'll like.
>>>
>>>
>>> In my post, there was a subliminal question, but it didn't reach your
>>> consciousness, I'm sorry. Here it is:
>>
>> It wasn't really a question, and the fact that you had mentioned that the
>> solution to the problem might be language dependent did register with me.
>>
>> I think its a pity that you chose to answer in what appears to be a rather
>> rude manner.
>
> That wasn't intended. Sorry again.
>
>
>>> What programming language do you use?
>>
>> C++. But I had already established before my original post that the
>> standard emacs indenting would not suit me. Perhaps I should have mentioned
>> this.
>
> c++-mode is derived from c-mode, you can configure c-offsets-alist and
> possibly define your own c-style in c-style-alist.
>
> The point here is that almost all the syntactic elements of C/C++ are
> already taken into account by the C indenting functions, so you only
> need to specify the indenting you want, and let the existing machinery
> do the work for you.
>
>
>
>>> Depending on the answer you give, you may well have nothing to program.
>>> Otherwise, you could do something like this:
>>>
>>> (defconst +space+ 32 "ASCII code for the space character")
>>>
>>> (defun my-language/indent-line ()
>>> (interactive)
>>> (let ((where (let ((m (make-marker))) (set-marker m (point)) m))
>>> (indent (my-language/get-indent-from-some-parsing-around (point))))
>>> (beginning-of-line)
>>> (looking-at "^[ \t]*")
>>> (delete-region (beginning-of-line) (match-end))
>>> (goto-char (beginning-of-line))
>>> (insert (make-string indent +space+))
>>> (goto-char where)
>>> (set-marker where nil)))
>>>
>>>
>>> (local-set-key (kbd "TAB") 'my-language/indent-line)
>>>
>>>
>>> Of course, all the difficulty (or simplicity, depends on your language)
>>> is in implementing my-language/get-indent-from-some-parsing-around.
>>>
>>>
>>
>> Thanks for this.
>> I'll need to read it and understand it before I use it, but it looks like a
>> good starting point.
>
> Well, C++ is quite difficult to parse, so you should really first try
> to configure the existing emacs C indentation feature.
>
> However, if you want to write your own parser, you may use the
> bovinator from cedet: http://cedet.sourceforge.net/
> http://cedet.sourceforge.net/semantic.shtml
One can't help but think that that advice is so far from reality for
someone who has just started using emacs that it must be meant as a joke
:-;
Besides which, does cedet not parse c++ already?
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Tabs and Spaces
2009-05-25 15:10 ` Teemu Likonen
@ 2009-05-25 15:58 ` Chris Gordon-Smith
2009-05-25 16:38 ` Pascal J. Bourguignon
0 siblings, 1 reply; 22+ messages in thread
From: Chris Gordon-Smith @ 2009-05-25 15:58 UTC (permalink / raw)
To: help-gnu-emacs
Teemu Likonen <tlikonen@iki.fi> wrote:
> On 2009-05-25 14:58 (UTC), Chris Gordon-Smith wrote:
>
>> C++. But I had already established before my original post that the
>> standard emacs indenting would not suit me. Perhaps I should have
>> mentioned this.
>
> Fortunately C++ indentation is very much configurable. There are several
> predefined styles which you can change with "C-c ." (c-set-style)
> command. If none of them suit you you can create your own. For more info
> see the CC Mode info node
>
> C-h i d m CC Mode RET
Thanks.
I think the complicating factor for me is that I use my own syntax, with
macros instead of curly brackets ({}). This is not generally liked in the
C++ world, but it works well for me. For example:-
#define THEN { // Macro for modified syntax
// etc...
int x = 10;
if (x ==9)
THEN
// Do Something
ELSEIF (x == 9)
THEN
// Do something else
ELSE
// Do yet another thisg
ENDIF
I doubt whether any of the existing indenting styles can cope with this, so
I suppose I'll need to write a new configuration.
Until I know how to do this, I would like a very simple behaviour in which
pressing tab simply causes the relevant number of spaces to be inserted.
Chris Gordon-Smith
www.simsoup.info
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Tabs and Spaces
2009-05-25 15:36 ` Richard Riley
@ 2009-05-25 16:10 ` Pascal J. Bourguignon
2009-05-25 16:19 ` Richard Riley
0 siblings, 1 reply; 22+ messages in thread
From: Pascal J. Bourguignon @ 2009-05-25 16:10 UTC (permalink / raw)
To: help-gnu-emacs
Richard Riley <rileyrgdev@googlemail.com> writes:
>> [...removed a whole thread quotation...]
>
> One can't help but think that that advice is so far from reality for
> someone who has just started using emacs that it must be meant as a joke
> :-;
Which one?
I explicitely advised several times to configure c-offsets-alist.
> Besides which, does cedet not parse c++ already?
Besides the OP mentionned he was a _programmer_ who intended to write
his own parser! (At least that's what I understood).
--
__Pascal Bourguignon__
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Tabs and Spaces
2009-05-25 10:48 Tabs and Spaces Chris Gordon-Smith
2009-05-25 11:48 ` Pascal J. Bourguignon
@ 2009-05-25 16:15 ` B Smith-Mannschott
2009-05-25 17:03 ` Drew Adams
` (3 subsequent siblings)
5 siblings, 0 replies; 22+ messages in thread
From: B Smith-Mannschott @ 2009-05-25 16:15 UTC (permalink / raw)
To: help-gnu-emacs
On Mon, May 25, 2009 at 12:48, Chris Gordon-Smith
<use.address@my.homepage.invalid> wrote:
> Hello All
>
> I have recenly started using emacs for programming, after years using
> KDevelop. One problem I have is indenting code. I have my own indentation
> style. and ideally I would like to setup emacs to support it automatically.
> However, in the short term I'll settle for having emacs convert a TAB
> keypress into the correct number of spaces to fill whitespace up to the
> next tabstop.
>
> At the moment I have
>
> (global-set-key (kbd "TAB") 'self-insert-command)
>
> in my .emacs to force insertion of a tab, but I have to keep invoking
> untabify manually (otherwise my code looks misaligned when I upload it to
> Google Code).
>
> Can anyone help.
Parital solution:
By default, emacs has a nasty habit of indenting with a mix of tabs
and spaces. you can disable this by setting indent-tabs-mode to nil.
You can do this via M-x customize-apropos or by sprinkling this bit of
elisp into your .emacs:
(setq-default
indent-tabs-mode nil ;;; http://www.emacswiki.org/cgi-bin/wiki/TabsAreEvil
)
// Ben
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Tabs and Spaces
2009-05-25 16:10 ` Pascal J. Bourguignon
@ 2009-05-25 16:19 ` Richard Riley
0 siblings, 0 replies; 22+ messages in thread
From: Richard Riley @ 2009-05-25 16:19 UTC (permalink / raw)
To: help-gnu-emacs
pjb@informatimago.com (Pascal J. Bourguignon) writes:
> Richard Riley <rileyrgdev@googlemail.com> writes:
>
>>> [...removed a whole thread quotation...]
>>
>> One can't help but think that that advice is so far from reality for
>> someone who has just started using emacs that it must be meant as a joke
>> :-;
>
> Which one?
The bit you snipped directly in front of my comment :-;
,----
| > However, if you want to write your own parser, you may use the
| > bovinator from cedet: http://cedet.sourceforge.net/
| > http://cedet.sourceforge.net/semantic.shtml
`----
>
> I explicitely advised several times to configure c-offsets-alist.
>
>
>> Besides which, does cedet not parse c++ already?
>
> Besides the OP mentionned he was a _programmer_ who intended to write
> his own parser! (At least that's what I understood).
But not for Emacs to parse C++ using the horrendously complicated (but
powerful) CEDET framework when he has a mere smattering of Elisp
knowledge. I was just being glib. Slow day at the keyboard ...
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Tabs and Spaces
2009-05-25 15:58 ` Chris Gordon-Smith
@ 2009-05-25 16:38 ` Pascal J. Bourguignon
0 siblings, 0 replies; 22+ messages in thread
From: Pascal J. Bourguignon @ 2009-05-25 16:38 UTC (permalink / raw)
To: help-gnu-emacs
use.address@my.homepage.invalid (Chris Gordon-Smith) writes:
> Teemu Likonen <tlikonen@iki.fi> wrote:
>> On 2009-05-25 14:58 (UTC), Chris Gordon-Smith wrote:
>>
>>> C++. But I had already established before my original post that the
>>> standard emacs indenting would not suit me. Perhaps I should have
>>> mentioned this.
>>
>> Fortunately C++ indentation is very much configurable. There are several
>> predefined styles which you can change with "C-c ." (c-set-style)
>> command. If none of them suit you you can create your own. For more info
>> see the CC Mode info node
>>
>> C-h i d m CC Mode RET
>
> Thanks.
>
> I think the complicating factor for me is that I use my own syntax, with
> macros instead of curly brackets ({}). This is not generally liked in the
> C++ world, but it works well for me. For example:-
>
> #define THEN { // Macro for modified syntax
> // etc...
>
> int x = 10;
> if (x ==9)
> THEN
> // Do Something
> ELSEIF (x == 9)
> THEN
> // Do something else
> ELSE
> // Do yet another thisg
> ENDIF
>
> I doubt whether any of the existing indenting styles can cope with this, so
> I suppose I'll need to write a new configuration.
>
> Until I know how to do this, I would like a very simple behaviour in which
> pressing tab simply causes the relevant number of spaces to be inserted.
Yes, indeed you will have to implement your own parsing.
If your macros could result in a syntax close enough to Pascal or
Modula-2 you could try to use one of these language mode. But it
won't work well until you code your own indentation stuff.
Check cedet!
--
__Pascal Bourguignon__
^ permalink raw reply [flat|nested] 22+ messages in thread
* RE: Tabs and Spaces
2009-05-25 10:48 Tabs and Spaces Chris Gordon-Smith
2009-05-25 11:48 ` Pascal J. Bourguignon
2009-05-25 16:15 ` B Smith-Mannschott
@ 2009-05-25 17:03 ` Drew Adams
2009-05-25 21:45 ` Chris Gordon-Smith
` (2 subsequent siblings)
5 siblings, 0 replies; 22+ messages in thread
From: Drew Adams @ 2009-05-25 17:03 UTC (permalink / raw)
To: 'Chris Gordon-Smith', help-gnu-emacs
> having emacs convert a TAB keypress into the correct number
> of spaces
(setq indent-tabs-mode nil)
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Tabs and Spaces
2009-05-25 10:48 Tabs and Spaces Chris Gordon-Smith
` (2 preceding siblings ...)
2009-05-25 17:03 ` Drew Adams
@ 2009-05-25 21:45 ` Chris Gordon-Smith
2009-05-26 1:08 ` Pascal J. Bourguignon
[not found] ` <mailman.7772.1243271023.31690.help-gnu-emacs@gnu.org>
[not found] ` <mailman.7771.1243268169.31690.help-gnu-emacs@gnu.org>
5 siblings, 1 reply; 22+ messages in thread
From: Chris Gordon-Smith @ 2009-05-25 21:45 UTC (permalink / raw)
To: help-gnu-emacs
Chris Gordon-Smith <use.address@my.homepage.invalid> wrote:
> Hello All
>
> I have recenly started using emacs for programming, after years using
> KDevelop. One problem I have is indenting code. I have my own indentation
> style. and ideally I would like to setup emacs to support it automatically.
> However, in the short term I'll settle for having emacs convert a TAB
> keypress into the correct number of spaces to fill whitespace up to the
> next tabstop.
I now have a solution. It turned out to be simpler than I thought:
(global-set-key (kbd "TAB") 'tab-to-tab-stop)
(setq-default indent-tabs-mode nil)
Chris Gordon-Smith
www.simsoup.info
>
> At the moment I have
>
> (global-set-key (kbd "TAB") 'self-insert-command)
>
> in my .emacs to force insertion of a tab, but I have to keep invoking
> untabify manually (otherwise my code looks misaligned when I upload it to
> Google Code).
>
> Can anyone help.
>
> Chris Gordon-Smith
> www.simsoup.info
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Tabs and Spaces
[not found] ` <mailman.7772.1243271023.31690.help-gnu-emacs@gnu.org>
@ 2009-05-25 21:48 ` Chris Gordon-Smith
0 siblings, 0 replies; 22+ messages in thread
From: Chris Gordon-Smith @ 2009-05-25 21:48 UTC (permalink / raw)
To: help-gnu-emacs
Drew Adams <drew.adams@oracle.com> wrote:
>> having emacs convert a TAB keypress into the correct number
>> of spaces
>
> (setq indent-tabs-mode nil)
>
Thanks. This on its own didn't work for me. I also had to use
tab-to-tab-stop (and setq-default rather than setq).
Chris Gordon-Smith
www.simsoup.info
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Tabs and Spaces
2009-05-25 21:45 ` Chris Gordon-Smith
@ 2009-05-26 1:08 ` Pascal J. Bourguignon
2009-05-26 21:31 ` Chris Gordon-Smith
0 siblings, 1 reply; 22+ messages in thread
From: Pascal J. Bourguignon @ 2009-05-26 1:08 UTC (permalink / raw)
To: help-gnu-emacs
use.address@my.homepage.invalid (Chris Gordon-Smith) writes:
> I now have a solution. It turned out to be simpler than I thought:
>
> (global-set-key (kbd "TAB") 'tab-to-tab-stop)
> (setq-default indent-tabs-mode nil)
But if you do that, you will have to indent by hand all your code!?!
--
__Pascal Bourguignon__
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Tabs and Spaces
[not found] ` <mailman.7771.1243268169.31690.help-gnu-emacs@gnu.org>
@ 2009-05-26 12:29 ` Francis Moreau
0 siblings, 0 replies; 22+ messages in thread
From: Francis Moreau @ 2009-05-26 12:29 UTC (permalink / raw)
To: help-gnu-emacs
On 25 mai, 18:15, B Smith-Mannschott <bsmith.o...@gmail.com> wrote:
> On Mon, May 25, 2009 at 12:48, Chris Gordon-Smith
>
>
>
> <use.addr...@my.homepage.invalid> wrote:
> > Hello All
>
> > I have recenly started using emacs for programming, after years using
> > KDevelop. One problem I have is indenting code. I have my own indentation
> > style. and ideally I would like to setup emacs to support it automatically.
> > However, in the short term I'll settle for having emacs convert a TAB
> > keypress into the correct number of spaces to fill whitespace up to the
> > next tabstop.
>
> > At the moment I have
>
> > (global-set-key (kbd "TAB") 'self-insert-command)
>
> > in my .emacs to force insertion of a tab, but I have to keep invoking
> > untabify manually (otherwise my code looks misaligned when I upload it to
> > Google Code).
>
> > Can anyone help.
>
> Parital solution:
>
> By default, emacs has a nasty habit of indenting with a mix of tabs
> and spaces.
I agree.
> you can disable this by setting indent-tabs-mode to nil.
> You can do this via M-x customize-apropos or by sprinkling this bit of
> elisp into your .emacs:
But what should be done if instead I want to keep tabs but don't want
to keep the alignment (silly) thing ?
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Tabs and Spaces
2009-05-26 1:08 ` Pascal J. Bourguignon
@ 2009-05-26 21:31 ` Chris Gordon-Smith
2009-05-26 22:03 ` Drew Adams
[not found] ` <mailman.7877.1243375379.31690.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 22+ messages in thread
From: Chris Gordon-Smith @ 2009-05-26 21:31 UTC (permalink / raw)
To: help-gnu-emacs
Pascal J. Bourguignon <pjb@informatimago.com> wrote:
> use.address@my.homepage.invalid (Chris Gordon-Smith) writes:
>> I now have a solution. It turned out to be simpler than I thought:
>>
>> (global-set-key (kbd "TAB") 'tab-to-tab-stop)
>> (setq-default indent-tabs-mode nil)
>
> But if you do that, you will have to indent by hand all your code!?!
>
Yes. This is certainly not ideal, but it is workable. Since it is unlikely
that the built in emacs parsing / indentation will be able to handle my
modified syntax, I think I have no choice for the short term. For the
longer term, I definitely want to work out how to customise the indentation
for my purposes. But I think for that I will need a lot more knowledge of
Emacs and Lisp than I currently have.
Chris Gordon-Smith
www.simsoup.info
^ permalink raw reply [flat|nested] 22+ messages in thread
* RE: Tabs and Spaces
2009-05-26 21:31 ` Chris Gordon-Smith
@ 2009-05-26 22:03 ` Drew Adams
[not found] ` <mailman.7877.1243375379.31690.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 22+ messages in thread
From: Drew Adams @ 2009-05-26 22:03 UTC (permalink / raw)
To: 'Chris Gordon-Smith', help-gnu-emacs
> Since it is unlikely that the built in emacs parsing /
> indentation will be able to handle my modified syntax,...
> For the longer term, I definitely want to work out how
> to customise the indentation for my purposes.
It's not hard, actually. It's just not well documented (IMO).
See the Emacs manual, node `Lisp Indent'.
Personally, I think the explanation given there is inadequate, and this (or
more) should really be in the Elisp manual (you need some Lisp code to customize
indentation of various Lisp sexps) - there is nothing in the Lisp manual about
it. I've just filed a doc bug about this.
After reading that node, `grep' the Lisp source code for places where it puts
property `lisp-indent-function' on various function and macro symbols. Just copy
what's done there. See also `C-h f lisp-indent-function', which describes the
function that uses the symbol property.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Tabs and Spaces
[not found] ` <mailman.7877.1243375379.31690.help-gnu-emacs@gnu.org>
@ 2009-05-26 22:40 ` Pascal J. Bourguignon
2009-05-27 20:38 ` Chris Gordon-Smith
0 siblings, 1 reply; 22+ messages in thread
From: Pascal J. Bourguignon @ 2009-05-26 22:40 UTC (permalink / raw)
To: help-gnu-emacs
"Drew Adams" <drew.adams@oracle.com> writes:
>> Since it is unlikely that the built in emacs parsing /
>> indentation will be able to handle my modified syntax,...
>> For the longer term, I definitely want to work out how
>> to customise the indentation for my purposes.
>
> It's not hard, actually. It's just not well documented (IMO).
>
> See the Emacs manual, node `Lisp Indent'.
>
> Personally, I think the explanation given there is inadequate, and this (or
> more) should really be in the Elisp manual (you need some Lisp code to customize
> indentation of various Lisp sexps) - there is nothing in the Lisp manual about
> it. I've just filed a doc bug about this.
>
> After reading that node, `grep' the Lisp source code for places where it puts
> property `lisp-indent-function' on various function and macro symbols. Just copy
> what's done there. See also `C-h f lisp-indent-function', which describes the
> function that uses the symbol property.
Well sexp indenting is the easy special case.
I would advise rather to have a look at the pascal.el source (where
pascal-mode and pascal-indent-line are defined). This is probably
closer to what Chris would need to implement.
However, there is one thing that could be done cf. sexps, is to
implement the forward-sexp-function hook. This is a function that
should move the cursor forward (or backward depending on its argument)
over a number of "sexp" that is, of expressions in the current
language. So given a cursor before a BEGIN, it would have to move
after the matching END, and so on for all the kinds of brackets the
languages allows (for xml, it would have to move from before <tag> to
after </tag>). In the case of C++ however, there are a lot of
different brackets, so parsing and matching them is hard and
puzzling. (And what to do of x<a<b>> (vs. x<a<b> >)).
Anyways, with this hook implemented, a lot of existing functions and
commands will start to work meaningfully in these buffers, and the
generic indenting algorithm may be usable.
--
__Pascal Bourguignon__
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: Tabs and Spaces
2009-05-26 22:40 ` Pascal J. Bourguignon
@ 2009-05-27 20:38 ` Chris Gordon-Smith
0 siblings, 0 replies; 22+ messages in thread
From: Chris Gordon-Smith @ 2009-05-27 20:38 UTC (permalink / raw)
To: help-gnu-emacs
Pascal J. Bourguignon <pjb@informatimago.com> wrote:
> "Drew Adams" <drew.adams@oracle.com> writes:
>
>>> Since it is unlikely that the built in emacs parsing /
>>> indentation will be able to handle my modified syntax,...
>>> For the longer term, I definitely want to work out how
>>> to customise the indentation for my purposes.
>>
>> It's not hard, actually. It's just not well documented (IMO).
>>
>> See the Emacs manual, node `Lisp Indent'.
>>
>> Personally, I think the explanation given there is inadequate, and this (or
>> more) should really be in the Elisp manual (you need some Lisp code to customize
>> indentation of various Lisp sexps) - there is nothing in the Lisp manual about
>> it. I've just filed a doc bug about this.
>>
>> After reading that node, `grep' the Lisp source code for places where it puts
>> property `lisp-indent-function' on various function and macro symbols. Just copy
>> what's done there. See also `C-h f lisp-indent-function', which describes the
>> function that uses the symbol property.
>
> Well sexp indenting is the easy special case.
>
> I would advise rather to have a look at the pascal.el source (where
> pascal-mode and pascal-indent-line are defined). This is probably
> closer to what Chris would need to implement.
>
> However, there is one thing that could be done cf. sexps, is to
> implement the forward-sexp-function hook. This is a function that
> should move the cursor forward (or backward depending on its argument)
> over a number of "sexp" that is, of expressions in the current
> language. So given a cursor before a BEGIN, it would have to move
> after the matching END, and so on for all the kinds of brackets the
> languages allows (for xml, it would have to move from before <tag> to
> after </tag>). In the case of C++ however, there are a lot of
> different brackets, so parsing and matching them is hard and
> puzzling. (And what to do of x<a<b>> (vs. x<a<b> >)).
>
> Anyways, with this hook implemented, a lot of existing functions and
> commands will start to work meaningfully in these buffers, and the
> generic indenting algorithm may be usable.
>
Thanks to you both for this. I've had a quick look at Lisp indent and
pascal.el. This will have to be a 'background' project to pick up every so
often. The reality is that while I would like to get auto indentation
working, my current manual approach works and there are a lot of other
things I need to do.
That being said, it looks like a good way to pick up Emacs Lisp on a real
problem with a real benefit at the end. At the moment though I have very
little understanding of Lisp; its as though it is a useful tool but I don't
even know which end of it to pick up!
One thought that occurred to me is that if I could get the C++ indentation
to treat BEGIN and THEN in the same way as it treats "{", I might be able
to make some headway. Ditto for ENDIF, END and "}". ELSE could be
interesting. I define it as "} else {".
Chris Gordon-Smith
www.simsoup.info
^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2009-05-27 20:38 UTC | newest]
Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-25 10:48 Tabs and Spaces Chris Gordon-Smith
2009-05-25 11:48 ` Pascal J. Bourguignon
2009-05-25 12:17 ` Chris Gordon-Smith
2009-05-25 13:48 ` Pascal J. Bourguignon
2009-05-25 14:58 ` Chris Gordon-Smith
2009-05-25 15:10 ` Teemu Likonen
2009-05-25 15:58 ` Chris Gordon-Smith
2009-05-25 16:38 ` Pascal J. Bourguignon
2009-05-25 15:14 ` Pascal J. Bourguignon
2009-05-25 15:36 ` Richard Riley
2009-05-25 16:10 ` Pascal J. Bourguignon
2009-05-25 16:19 ` Richard Riley
2009-05-25 16:15 ` B Smith-Mannschott
2009-05-25 17:03 ` Drew Adams
2009-05-25 21:45 ` Chris Gordon-Smith
2009-05-26 1:08 ` Pascal J. Bourguignon
2009-05-26 21:31 ` Chris Gordon-Smith
2009-05-26 22:03 ` Drew Adams
[not found] ` <mailman.7877.1243375379.31690.help-gnu-emacs@gnu.org>
2009-05-26 22:40 ` Pascal J. Bourguignon
2009-05-27 20:38 ` Chris Gordon-Smith
[not found] ` <mailman.7772.1243271023.31690.help-gnu-emacs@gnu.org>
2009-05-25 21:48 ` Chris Gordon-Smith
[not found] ` <mailman.7771.1243268169.31690.help-gnu-emacs@gnu.org>
2009-05-26 12:29 ` Francis Moreau
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).