How to disable auto-indentation on newline in js2-mode? - emacs

I'm editing React .jsx files, and I don't want to indent on newline, how to disable it?

M-x electric-indent-local-mode should do it if you're using Emacs-24.4.

What seems to work in Emacs 25.1.1 is setting electric-layout-mode to -1.
So In js2-mode-hook add:
(add-hook 'js2-mode-hook (lambda () (electric-layout-mode -1)))

Related

How to turn off ‘tab’ highlighting in go buffers?

I’ve just started writing Go programs in Emacs. How can I turn off tabs highlighting in go-mode buffers? I use «whitespace» for whitespace chars highlighting. Go btw is the only mode where I don’t want tabs highlighted since tabs are standard formatting in Go.
Sincerely, Pavel.
To be clear, you're doing something like
(require 'whitespace)
(global-whitespace-mode t)
right? You can disable whitespace-mode for go-mode with
(setq whitespace-global-modes '(not go-mode))
There is a related question on emacs stack exchange.
I found that this
(add-hook 'go-mode-hook
(lambda ()
(add-hook 'before-save-hook 'gofmt-before-save)
(setq whitespace-style '(face empty trailing lines-tail))
(setq tab-width 4)
(setq indent-tabs-mode 1)))
Worked a bit better for me. Leaves whitespace-mode on but doesn't highlight tabs. Also runs go fmt before save and sets tab width to 4. I'm using prelude.
Add this line
(whitespace-toggle-options '(tabs)))
To your go-mode hook e.g
(use-package go-mode
:preface
(defun go-mode-config ()
(whitespace-toggle-options '(tabs)))
:config
(add-hook 'go-mode-hook (lambda ()
(go-mode-config))))
Taken from prelue go config

How to make Emacs not highlight trailing whitespace in term?

I'm using this in my .emacs config
'(show-trailing-whitespace t)
And I'm generally very happy with it.
The only problem is that it highlights whitespace when I'm in 'M-x term' buffer and I have no control over that whitespace. How to prevent this?
Use this:
(add-hook
'term-mode-hook
(lambda() (setq show-trailing-whitespace nil)))

Funky indentation in SML mode

I installed SML Mode in Emacs and the indentation is messed up. I disabled all my .emacs customizations, but that didn't make any difference. At the end of each line in the code below, I used C-j, which is mapped to newline-and-indent.
If I highlight everything and reindent (C-M-\), the result makes more sense:
I'm using Emacs 24.1.1 and SML Mode 6.2 on Ubuntu 12.10. What should I do?
Don't use newline-and-indent.
You can use reindent-then-new-and-indent or electric-indent-mode instead.
try in the .emacs file:
(setq default-tab-width 4);
(setq-default indent-tabs-mode nil);
(global-set-key (kbd "TAB") 'self-insert-command);
I'm no wizard but that worked for me.
http://www.pement.org/emacs_tabs.htm
Following up on Stefan's (now 4 year old...) suggestion, you can auto-enable the minor mode electric-indent-mode for sml-mode by putting this:
(push (lambda () electric-indent-local-mode 1) sml-mode-hook)
somewhere in your emacs initialization code.
Or, you might prefer:
(use-package sml-mode
:config
(push (lambda () electric-indent-local-mode 1) sml-mode-hook))
This seems to me to produce reasonably sane behavior for indenting code in sml-mode.

whitespace-mode in minibuffer?

Is there a way I can turn on whitespace-mode in a minibuffer? I'm not sure I'll stick to it - but sometimes I need it. I tried to add-hook all the M-x apropos RET minibuffer hook RET:
(mapc
(lambda (language-mode-hook)
(add-hook language-mode-hook
(lambda () (interactive) (whitespace-mode 1))))
'(minibuffer-setup-hook
icicle-minibuffer-setup-hook
icomplete-minibuffer-setup-hook
ido-minibuffer-setup-hook
minibuffer-inactive-mode-hook))
but it doesn't work.
It looks like you've got something that should work, this worked for me:
(defun enable-ws-mode ()
(whitespace-mode 1))
(add-hook 'minibuffer-inactive-mode-hook 'enable-ws-mode)
as did the code you posted. Have you tried running Emacs without your initialization files?
emacs -q
emacs -q --no-site-init
and evaluating the code you had?
Perhaps this is only because it's been six years, but . . . with Emacs 26.3 I was able to add the regular whitespace mode command to the hook with no intermediating function:
(add-hook 'minibuffer-inactive-mode-hook 'whitespace-mode)
No fuss, no muss, works here.

emacs auto-fill-mode doesn't initialise

I want to enable line-wrapping without having to type 'M-x auto-fill-mode' everytime I start emacs. I've tried putting (setq auto-fill-mode 1) and (auto-fill-mode 1) in the .emacs file, but neither work. Why is this, and how do I fix it?
Thanks
It is a minor-mode so you need to enable it for the modes where you want it used. So, for example, if you want auto-fill-mode enabled in text mode, you need to add the following to your .emacs file:
(add-hook 'text-mode-hook '(lambda ()
(auto-fill-mode 1)))
auto-fill-mode is a minor mode so (setq auto-fill-mode 1) wont start it.
You can add a hook to start auto-fill-mode with the text-mode (with which it is normally used) or any other mode you normally use it with, by doing
(add-hook 'text-mode-hook 'turn-on-auto-fill)
Alternatively, if you want the auto-fill-mode on for all the files you edit. You can start it when any type of file is opened with:
(setq auto-mode-alist (cons '("*" . auto-fill-mode) auto-mode-alist))
But having it always on is irritating at times, so its better to bind the starting of the mode to a familiar key sequence
(global-set-key (kbd "C-c q") 'auto-fill-mode)