I'm new to emacs, and its indenting is driving me up the walls. It's too smart for its own good; it (incorrectly) thinks it knows how I want to format my source, but I don't have time to chase down every setting for every mode for every different language that I write code for; and many of those languages don't have any mode enabled at all.
Here's the behaviour I'd like:
setq
s.This would get me logical and consistent behaviour across all languages. It would leave the work of formatting the code to me, but that's OK, I've been doing that for 20 years, and I know how to make other macros that make it efficient. More importantly, it saves me from endless fiddling with configuration settings trying to get the automatic behaviour to suit my preferences. And my macros can rely on consistent behaviour so they work correctly in all modes.
Is the above possible? Surely someone else has done this before? Is there some minor mode out there that makes it so?
Here's the code:
(setq tab-width 4)
(defun plain-tab ()
(interactive)
(insert (make-string tab-width ?\ )))
(defun plain-ret ()
(interactive)
(looking-back "^\\( +\\).*")
(newline)
(insert (match-string 1)))
(defun plain-del ()
(interactive)
(backward-delete-char
(if (looking-back (format " \\{%d\\}" tab-width)) tab-width 1)))
(defvar all-the-mode-maps
'(c-mode-map c++-mode-map java-mode-map
js-mode-map emacs-lisp-mode-map
clojure-mode-map))
(require 'cc-mode)
(require 'js)
(require 'clojure-mode)
(eval `(mapc
(lambda(map)
(define-key map [tab] 'plain-tab)
(define-key map [return] 'plain-ret)
(define-key map [backspace] 'plain-del)
(define-key map "{" (lambda()(interactive)(insert "{")))
(define-key map "}" (lambda()(interactive)(insert "}"))))
(list ,@all-the-mode-maps)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With