Editor Configuration Snippets


Suppose your personal preferred indentation style is dissimilar from the Pidgin indentation style, but you're a team player and you want to use Pidgin indentation when working on Pidgin/libpurple/whatever. These snippets can help you with that.

(c-add-style "pidgin" '((tab-width . 8)
                        (c-tab-always-indent . t)
                        (c-basic-offset . 8)
                        (indent-tabs-mode . t)))

(defun pidgin-c-mode-init ()
  (if (or (posix-string-match "some/path/snippet" (buffer-file-name))
          (posix-string-match "code/pidgin" (buffer-file-name)))
      (c-set-style "pidgin")))

(add-hook 'c-mode-hook 'pidgin-c-mode-init)

Make sure this hook runs after your normal setup hook, if your normal hook sets a style. The or is included just to show how to match multiple paths. You may perform the selection however you like, path snippets just happen to be useful given my filesystem organization. -- elb

If you're using Emacs23+, there's an arguably cleaner way to set up project-specific configuration via directory variables. All you need to do is to add the customization to .dir-locals.el file to the root dir of your pidgin clone and it will be applied to all files below that dir. For example, given the pidgin style definition above, my setup is as follows (additional c++-mode config is necessary if you associate *.h files with it, like I do):

((c-mode . ((c-file-style . "pidgin")))
 (c++-mode . ((c-file-style . "pidgin")
              (mode . c))))

-- immerrr


Regardless of what the indentation style and tab width convention is in the rest of the tree, the ChangeLog and NEWS files should always use a tab width of 8. This may not be the right or best .vimrc snippet to do this, but it works. Insert this snippet into .vimrc (.gvimrc for you GUI addicts) after your existing tab configuration:

autocmd! BufReadPost,BufNewFile */ChangeLog call <SID>ChangeLogNewsOptions()
autocmd! BufReadPost,BufNewFile */NEWS call <SID>ChangeLogNewsOptions()

function! <SID>ChangeLogNewsOptions()
    " These settings affect ChangeLog and NEWS files only
    setlocal sw=8
    setlocal tabstop=8

It's ugly, but it works. -- rekkanoryo

Last modified 4 years ago Last modified on 06/12/13 18:41:44
All information, including names and email addresses, entered onto this website or sent to mailing lists affiliated with this website will be public. Do not post confidential information, especially passwords!