Funky indentation in SML mode - emacs

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.

Related

disable autocomplete for specific filetype or language in emacs [duplicate]

I am using Emacs 24 and would like to disable auto-complete mode while in python-mode so it does not conflict with jedi. How do I go about doing this (sadly I do not know Emacs Lisp). Below are my current settings regarding auto-complete in init.el:
;; auto-complete settings
(require 'auto-complete)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
(require 'auto-complete-config)
(ac-config-default)
; Start auto-completion after 2 characters of a word
(setq ac-auto-start 2)
; case sensitivity is important when finding matches
(setq ac-ignore-case nil)
Thanks.
(ac-config-default) turns on global-auto-complete-mode, to stop (auto-complete-mode) from being called in python mode you can write an advice for it.
(defadvice auto-complete-mode (around disable-auto-complete-for-python)
(unless (eq major-mode 'python-mode) ad-do-it))
(ad-activate 'auto-complete-mode)
Also I am not sure this is what you want, since Jedi use auto-complete-mode as Dmitry pointed out in the comment, there should not be conflicts.
I think I had a similar problem: my yellow Jedi popups with Python-specific content were taken over by grey popups from a more general auto-complete feature. Hence, I could choose non-Python related options, but not the Python-specific ones.
What helped for me was ensuring that auto-complete-mode is disabled in Python mode:
(add-hook 'python-mode-hook (lambda () (auto-complete-mode -1)))

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

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 folding/unfolding R code

Is there an Emacs minor-mode (or piece of elisp code) that lets you selectively hide/show environments while in Sweave (Sweave = R + LaTeX)?
For instance, I would like to move to the beginning of a code block (<<>>), hit a keystroke, and have the contents of the environment hidden from view.
Is this possible? I just tried hs-minor-mode, allout-mode, and outline-minor-mode, but most of them don't recognize R environments.
I also tryed org-mode that works great for folding/unfolding but, do not support the LaTeX highlighting code for expression like: \cite{}; \ref{}; \ce{} ...
Best
Riccardo
--EDIT--
I tried for some day to use emacs-folding-mode but, because I work on a very long code (more than 2000 rows), folding mode "goes crazy" and for example misunderstand the mining of some special character (i.e. $), that has very different use both in R than LaTeX. I think the problem is intrinsic to Sweave, because in the same buffer I have R code and LaTeX code together.
So, now I'm testing emacs outline minor mode. But when I move through R from LaTeX (and vice versa) all the outlined part were unfolded despite I write in my .emacs:
(defun turn-on-outline-minor-mode ()
(outline-minor-mode 1))
(add-hook 'ess-mode-hook 'turn-on-outline-minor-mode)
(add-hook 'LaTeX-mode-hook 'turn-on-outline-minor-mode)
(add-hook 'latex-mode-hook 'turn-on-outline-minor-mode)
(setq outline-minor-mode-prefix "\C-c\C-o")
Do you have any suggestions??
Regards
--EDIT 2--
It seems to work:
(load "folding" 'nomessage 'noerror)
(folding-mode-add-find-file-hook)
(add-hook 'LaTeX-mode-hook 'folding-mode)
(add-hook 'ess-mode-hook 'folding-mode)
(folding-add-to-marks-list 'ess-mode "#{{{ " "#}}}" " ")
I don't know if is right that, when you leave the chunk, it is automatically unfolded.
There's a generic folding mode here: http://www.emacswiki.org/emacs/FoldingMode
I have had very good results with the hideshow hs-minor-mode, these are the lines I basically use in my ~/.emacs.d/init.el:
(add-hook 'ess-mode-hook 'hs-minor-mode)
(eval-after-load 'hideshow
'(progn
(global-set-key (kbd "C-+") 'hs-toggle-hiding)))

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)