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

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

Related

How to revert indent-tabs-mode when editing makefiles in emacs?

I've got the following in my .emacs since for most source code I use spaces only:
(add-hook 'prog-mode-hook
(lambda ()
(setq indent-tabs-mode nil)))
This messes up my makefiles though since they require tabs. How do I work around this so that I get spaces by default for all source code, but makefiles retain tabs?
You can always add an add-hook for makefile-mode to change it back.
(add-hook 'makefile-mode-hook
(lambda ()
(setq indent-tabs-mode t)))

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)))

Emacs BSD/Allman Style with 4 Space Tabs?

Using this emacs lisp setting one ends up with BSD/Allman style braces but introduces tabs with 8 spaces.
(add-hook 'c-mode-hook
(lambda ()
(c-set-style "linux")))
How do I keep the Allman style braces but keep the tab spaces at 4?
I don't use c-set-style, so maybe this advice doesn't fit your environment. I have in my init file:
(custom-set-variables
...
'(c-basic-offset 8)
...)
So, setting c-basic-offset to 4 after c-set-style might do the trick:
(add-hook 'c-mode-hook
(lambda ()
(c-set-style "linux")
(setq c-basic-offset 4)))
Look at C-h f c-set-style. Maybe, playing around with DONT-OVERRIDE might help also.

Configure C whitespace and Python whitspace independently in Emacs

I would like to configure my Emacs whitespace options independently for C and python files, because the indent highlighting (space before tabs, etc.) does not apply to the Python coding style. I currently set the whitespace variables globally, but would like a separate (minimal) configuration for Python. Here is the relevant part of my .emacs:
(require 'whitespace)
(setq whitespace-line-column 80)
(setq whitespace-style '(face lines-tail indentation trailing space-before-tab))
(add-hook 'c-mode-hook 'whitespace-mode)
This works for C. Preferably I would have '(face lines-tail trailing) for Python, but I don't know how to setq just for a specific mode. What is the correct way to do this? Thanks. Using Emacs 23 in Ubuntu.
I got it to work by putting the settings into the hook along with the evocation of whitespace-mode:
(add-hook 'python-mode-hook
(lambda ()
(progn
(setq whitespace-line-column 79)
(setq whitespace-style '(face lines-tail))
(whitespace-mode))))
Perhaps using File Local Variables could help you?

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)