all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: use.address@my.homepage.invalid (Chris Gordon-Smith)
To: help-gnu-emacs@gnu.org
Subject: Re: Tabs and Spaces
Date: 25 May 2009 14:58:21 GMT	[thread overview]
Message-ID: <77vq0cF1jh3k6U1@mid.individual.net> (raw)
In-Reply-To: 7czld19ttv.fsf@pbourguignon.anevia.com

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



  reply	other threads:[~2009-05-25 14:58 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=77vq0cF1jh3k6U1@mid.individual.net \
    --to=use.address@my.homepage.invalid \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.