emacs can't turn on minor-mode automatically - emacs

I want irony-mode be turned on automatically in c-mode. But I have tried two ways, both fail. Can someone teach me? I don't like to type M-x irony-mode always.
1:
(require 'irony)
(defun my:irony-init ()
(irony-mode 1))
(add-hook 'c++-mode-hook 'my:irony-init)
(add-hook 'c-mode-hook 'my:irony-init)
OR 2:
(require 'irony)
(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'c-mode-hook 'irony-mode)
I find not only irony-mode, but also ggtags and flycheck can't load through add-hook. I have (add-hook 'c-mode-hook 'flycheck-mode), but it doesn't work. Can someone help me? My .emacs.d has uploaded to github:https://github.com/cfampc/emacs.d。 My irony-mode is configured in .emacs.d/custom/c-settings.el and flycheck ggtags is in .emacs.d//custom/edit-settings.el. Before I can have ggtags-mode auto-load in C. Now, If I add (add-hook 'c-mode-common-hook 'irony-mode) after (load ...) all of my config file, it does work. But if I add it in .emacs.d/custom/c-settings.el , It doesn't work. why?

That should work fine, so you should recursively bisect your config to find the source of the problem.

Related

Having trouble getiting Tomorrow theme to work in Emacs

I have only recently started to use emacs. I have succesffully used a couple of different themes, but am having trouble getting Tomorrow to work.
Here's what I have done:
The .el files are in ~/.emacs.d/themes/
my-init.el:
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/")
(require 'color-theme-sanityinc-tomorrow)
(load-theme 'color-theme-sanityinc-tomorrow-night t)
I load this in .emacs by doing
(add-hook 'after-init-hook '(lambda ()
(load "~/.emacs.d/my-noexternals.el")
(load "~/.emacs.d/my-init.el") ))
When I reload emacs I see eval-buffer: Cannot open load file: no such file or directory, color-theme-sanityinc-tomorrow.
If color-theme-sanityinc-tomorrow.el is in ~/.emacs.d/themes/ you need to had:
(add-to-list 'load-path "~/.emacs.d/themes/")
before the require.
Regards

Emacs, how to auto turn on flyspell for LaTeX file

I use Emacs only for \LaTeX and python programming. Is there a way to automatically turn on flyspell-mode when I work on a .tex file, and turn on flyspell-prog-mode when I work on a .py file? How can I do this in my .emacs file?
Add those functions to hooks of python-mode and latex-mode
(require 'python)
;; If you use tex-mode
(require 'tex-mode)`
(add-hook 'latex-mode-hook 'flyspell-mode)
;; If you use AUCTeX
(load "auctex.el" nil t t)`
(add-hook 'LaTeX-mode-hook 'flyspell-mode)
(add-hook 'python-mode-hook 'flyspell-prog-mode)
Something like this should work.
(setq auto-mode-alist (cons '("\\.tex\\'" . flyspell-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.py\\'" . flyspell-prog-mode) auto-mode-alist))

flyspell doesn't load with LaTeX file in emacs

Following this web page, I have edited my ~/.emacs file and added the line:
(add-hook 'LaTeX-mode-hook 'flyspell-mode)
However, flyspell doesn't start with LaTeX files. Why is that so?
I could not make this work:
(add-hook 'LaTeX-mode-hook 'flyspell-mode) or
(add-hook 'latex-mode-hook 'flyspell-mode)
But then I found this:
(add-hook 'LaTeX-mode-hook 'turn-on-flyspell)
-and it is working.
Emacs is case-sensitive; the hook should be written as latex-mode-hook. Try this:
(add-hook 'latex-mode-hook 'flyspell-mode)

Emacs auto-complete-mode at startup

I just install auto-complete-mode, however everytime I start emacs I have to M-x auto-complete-mode. Is there anyway to have it loaded automatically ?
My .emacs is as follows:
;; auto-complete
(add-to-list 'load-path "~/.emacs.d/")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d//ac-dict")
(ac-config-default)
Thanks
I think you can do it in various ways. To enable it globally you should use
(global-auto-complete-mode t)
But it uses auto-complete-mode-maybe, which turn AC on only those listed in ac-modes. You can add them manually just like this
(add-to-list 'ac-modes 'sql-mode)
You can make your own list if you wish AC be active only for few modes
(setq ac-modes '(c++-mode sql-mode))
Or rewrite it to have AC everywhere.
(defun auto-complete-mode-maybe ()
"No maybe for you. Only AC!"
(auto-complete-mode 1))
edited:
Autocomplete in minibuffer is bad. I think this will be better.
(defun auto-complete-mode-maybe ()
"No maybe for you. Only AC!"
(unless (minibufferp (current-buffer))
(auto-complete-mode 1)))
I just needed this:
(require 'auto-complete)
(global-auto-complete-mode t)
added to my .emacs.d/init.el file.
I installed auto-complete with the package manager. I'm using Emacs 24.

how to get started with viper/vimpulse?

I obtained a git clone of vimpulse and followed the instructions for installation. It basically says to put (require 'vimpulse) in my .emacs file - but this will start viper/vimpulse upon startup, so I tried to have vimpulse load only if I invoke viper-mode with (add-hook 'viper-mode-hook (lambda () (require 'vimpuse)). But when I do this visual mode does not work (tries to open file instead), so instead I now have something like (defun vimpulse-on () (interactive) (require 'vimpulse)). After that to toggle on and off I use C-z. Does that about sound right? So once vimpulse is loaded there's no equivalent of M-x viper-go-away and instead it's suspended until I hit C-z again... Also, any general tips with using viper/vimpulse would be appreciated! Thanks much in advance.
Edit: syntax error corrected. What I had tried was (add-hook 'viper-mode-hook (lambda () (require 'vimpulse)), which does not enable visual mode when viper-mode is started. v in normal-mode appears to be mapped to find-file (or ido-find-file).
(add-hook 'viper-load-hook
(lambda () (require 'vimpulse))
Just load vimpulse in the viper-load-hook.