0
votes

I'm new to emacs and trying desperately to make it behave the way I've gotten used to over the last few years with my IDEs.

I love a lot of the stuff it's doing but I am taking issue with its indentation practices.

What I want:

  • 4 spaces instead of tab
  • Pressing enter to put the cursor on the same column as where the previous line starts
  • Pressing tab inserts 4 spaces regardless of whatever the 'smart' indentation might think is correct
  • Pressing tab when using neotree-dir should try to resolve the path normally

I've managed to get 2/4 with https://github.com/zorgnax/regtab. Unfortunately, that solution breaks the path resolve in neotree.

EDIT: Thought it would make sense to show my .emacs config for this

(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(add-to-list 'load-path "~/.emacs.d/plugins/")
(load "regtab.el")
(define-globalized-minor-mode my-global-regtab-mode regtab-mode
  (lambda() (regtab-mode 1)))
(my-global-regtab-mode 1)
(when (fboundp 'electric-indent-mode) (electric-indent-mode -1))

Electric-indent-mode is turned off because if I indent a line in what it thinks is an 'invalid way', and then press RET, it 'corrects' my indentation. It does the same thing for the whole file when I use C-y

The reason you would want to make 'invalid' indentation is that certain libraries use what is essentially invalid html/js syntax.

EDIT2: Replacing

(when (fboundp 'electric-indent-mode) (electric-indent-mode -1))

with

(setq-default electric-indent-inhibit t)

has sort of helped. It no longer forces weird indentation onto me but now it at least indents somewhat when pressing RET and no longer ruins my indents when using C-y.

What's left now is to somehow achieve what regtab does without screwing up path resolve for M-x commands.

1

1 Answers

0
votes

Alright well, I kinda figured out my own stuff. If you have better solutions than what I'm about to list, please supply them.

1) Fixing crappy emacs indents: Get this file: https://github.com/zorgnax/regtab Put it in ~/.emacs.d/plugins/ (this file doesn't exist, make it.)

In your ~/.emacs file, add this:

(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(add-to-list 'load-path "~/.emacs.d/plugins/")
(load "regtab.el")
(define-globalized-minor-mode my-global-regtab-mode regtab-mode
  (lambda() (regtab-mode 1)))
(my-global-regtab-mode 1)
(when (fboundp 'electric-indent-mode) (electric-indent-mode -1))
(setq-default electric-indent-inhibit t)

2) Fixing side effects of the previous steps: Install hippie-expand Add the following to your ~/.emacs file

(global-set-key (kbd "C-M-/") 'my-expand-file-name-at-point)
(defun my-expand-file-name-at-point ()
  "Use hippie-expand to expand the filename"
  (interactive)
  (let ((hippie-expand-try-functions-list '(try-complete-file-name-partially try-complete-file-name)))
    (call-interactively 'hippie-expand)))

Now, when you want to complete a path in your M-x commands, use C-M-/