How to minimize .emacs configuration file?

I was wondering if anyone could help me with Minify of my .emacs file.

I am currently setting up where every language I use has a custom tab, for example, if I have a hook for Java, it will look like this.

;; Java hook
(defun e-java-mode-hook ()
    (setq tab-width 4)
    (setq indent-tabs-mode t)
    (define-key java-mode-map (kbd "") 'java-insert-tab))
(defun java-insert-tab (& optional arg)
    (interactive "P")
    (insert-tab arg))
(add-hook 'java-mode-hook' e-java-mode-hook)

And if I added another language like CSS or JavaScript, I would add another hook for CSS and another hook for JavaScript. So I was wondering if there is a global way to customize it to apply to any language?

I am currently running GNU Emacs 23.2.1 on Windows 7.

+5
source share
3 answers

I agree with Tyler; although this is a bit complicated, you will be better off in the long run if you try to understand and configure the default indentation features. The Emacs Wiki has good resources , and there are other relevant Q & As here when stack overflowing.

insert-tab , indent-region , .

, :

1) (java-insert-tab) (css-insert-tab) (javascript-insert-tab) .., ... , , , . .

2) (local-set-key ...) , (define-key (current-local-map) ...), , , , .

(defun my-coding-config ()
    (setq tab-width 4)
    (setq indent-tabs-mode t)
    (local-set-key (kbd "<tab>") 'my-insert-tab))

(defun my-insert-tab (&optional arg)
    (interactive "P")
    (insert-tab arg))

my-coding-config . , , :

;; Use my coding hook for all programming modes
(mapcar
 (lambda (language-mode-hook)
   (add-hook language-mode-hook 'my-coding-config))
 '(java-mode-hook
   javascript-mode-hook
   css-mode-hook
   ...))

3) C-h v tab-width RET, indent-tabs-mode, , : " -, ".

(set-default 'indent-tabs-mode t), . , , , .

+5

, . 4 , customize:

M-x customize-variable tab-width <ret>

, tab-width , . .

, , .emacs.

, , - , ? , Emacs, , .

, , , , :

C-h r m

( : h -elp, r - , m -enu item )

(info "(emacs)Indentation")
+2

espect.el , .

:


-. , , . ; , . , flyspell-prog , .mkn .
+1

All Articles