[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Tabs and Spaces
From: |
Pascal J. Bourguignon |
Subject: |
Re: Tabs and Spaces |
Date: |
Mon, 25 May 2009 15:48:44 +0200 |
User-agent: |
Gnus/5.101 (Gnus v5.10.10) Emacs/22.2 (gnu/linux) |
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__
- Tabs and Spaces, Chris Gordon-Smith, 2009/05/25
- Re: Tabs and Spaces, Pascal J. Bourguignon, 2009/05/25
- Re: Tabs and Spaces, Pascal J. Bourguignon, 2009/05/25
- Re: Tabs and Spaces, Richard Riley, 2009/05/25
- Re: Tabs and Spaces, Pascal J. Bourguignon, 2009/05/25
- Re: Tabs and Spaces, Richard Riley, 2009/05/25
Re: Tabs and Spaces, B Smith-Mannschott, 2009/05/25
RE: Tabs and Spaces, Drew Adams, 2009/05/25