I need associate from file.html to mode:
html-mode
emmet-mode
I am try this(but this not working):
(define-derived-mode my-html-mode
text-mode "Emmet+HTML"
(html-mode 1)
(emmet-mode 1))
(add-to-list 'auto-mode-alist '("\\.html\\'" . my-html-mode))
I'm going to assume that emmet-mode is a minor mode (you can't have more than one major mode in a single buffer).
html-mode is a major mode, and therefore its mode function takes no arguments, so (html-mode 1) is invalid (and should be causing an error. Were you seeing an error? "not working" doesn't tell us much.)
In Emacs 24+ you can associate minor modes with major modes by using the major mode's mode hook like so:
(add-hook 'html-mode 'emmet-mode)
See also https://stackoverflow.com/a/36416231
Since html-mode is a major mode and emmet-mode is a minor mode, you could derive your new mode from html-mode, and activate emmet-mode when my-html-mode is activated:
(define-derived-mode my-html-mode
html-mode "Emmet+HTML"
(emmet-mode 1))
(add-to-list 'auto-mode-alist '("\\.html\\'" . my-html-mode))
Related
I would like to have auto-complete-mode enabled by default. For some reason global-auto-complete-mode does not seem to have an effect on anything. What I have been doing to this point is manually enabling auto-complete-mode whenever I open a new buffer. What are my options here?
(add-hook 'prog-mode-hook #'auto-complete-mode)
global-auto-complete-mode is not as global as you may think it is. From the manual:
Enable auto-complete-mode automatically for specific modes
auto-complete-mode won't be enabled automatically for modes that are
not in ac-modes. So you need to set if necessary:
(add-to-list 'ac-modes 'brandnew-mode)
Thus if you would like to have, say, all buffers that are in prog-mode or in eshell-mode to automatically have auto-complete-mode enabled, you'd have to put the following in your .emacs file:
(add-to-list 'ac-modes 'prog-mode)
(add-to-list 'ac-modes 'eshell-mode)
I am trying to define a new mode which inherits everything from Org mode, called web mode.
Here is a preliminary amateur stab at this.
(defvar web-mode-syntax-table
org-mode-syntax-table
"Syntax table used while in `web-mode'.")
;; Create the keymap for this mode.
(defvar web-mode-map
org-mode-map
"Keymap for `web-mode'.")
(setq web-highlights
'(("Sin\\|Cos\\|Sum" . font-lock-function-name-face)
("Pi\\|Infinity" . font-lock-warning-face)))
;; set files ending in .web to open in web mode.
(add-to-list 'auto-mode-alist '("\\.web\\'" . web-mode))
(define-derived-mode web-mode org-mode "web-mode"
"Major mode based on Org-mode"
(kill-all-local-variables)
(setq major-mode 'web-mode)
(setq mode-name "Web Mode")
;; Tell font-lock mode about some things which
;; need to be highlighted.
(setq font-lock-defaults '(web-highlights))
)
However, when web-mode is loaded in a text file it seems identical to the plain-vanilla text mode. The key-words Sin, Cos and Sum get highlighted in blue correctly and the Pi and Infinity in bold red font, but otherwise nothing seems to have been inherited from Org mode, and seems indistinguishable from text mode.
Why is this?
I'm using spacemacs and tried to turn off company mode in org mode while keeping it in other major modes. I've tried the following:
(global-company-mode '(not org-mode))
but it's not working.
Disable from org-mode-hook (this method will work with pretty much any globalized minor mode and major mode):
(defun jpk/org-mode-hook ()
(company-mode -1))
(add-hook 'org-mode-hook #'jpk/org-mode-hook)
Or use company's configuration variable:
(setq company-global-modes '(not org-mode))
At the Spacemacs configuration layer level you can disable auto-completion layer for a set of layers with the following line in dotspacemacs-configuration-layers (for instance disabling auto-completion for both org and git)
(auto-completion :disabled-for org git)
Today I got my new PC (Windows 7, 32 bit) and installed Vincelt Goulets Emacs. The only other thing I did was updating Org-mode.
Now, I am stuck with auto-fill-mode on every time I start Emacs new, which I hate. I would like to turn auto-fill-mode off, for now and forever. I even deleted my .emacs file, but auto-fill-mode was still turned on.
The only solution that worked was (a) a nasty workaround or (b) always typing M-x auto-fill-mode every time I start Emacs anew.
Is there a solution?
To be clear, the only thing the current .emacs file contains is: '(inhibit-startup-screen t)
Add to your .emacs,
(auto-fill-mode -1)
If there are hooks for specific modes, you will need to zap those as well. My suspicion is that you do not actually have auto-fill-mode on by default in all modes, but with the information you have supplied, at least this should be a starting point.
A reasonable safeguard would be to also disable auto-fill mode from `text-mode-hook':
(remove-hook 'text-mode-hook #'turn-on-auto-fill)
You may need something similar for other modes as well.
Assuming that he has not made fundamental changes, you have several paths:
You can just turn off the mode globally in your .emacs file:
(turn-off-auto-fill)
;; ...or (auto-fill-mode -1)
Since Emacs of that vintage also turns on auto-fill for text-mode, add:
(remove-hook 'text-mode-hook 'turn-on-auto-fill)
That should account for all the default places, but check the major mode hooks if you have other modes enabling this automatically.
If you'd like to keep it turned-on in most text-mode while disable auto-fill in specific modes, e.g. org-mode in my case, you could use the following:
;; turn on auto-fill for text-mode
(add-hook 'text-mode-hook 'turn-on-auto-fill)
;; turn off auto-fill for org-mode
(add-hook 'org-mode-hook 'turn-off-auto-fill)
I load auto-complete mode like this:
(let ((ac-path "path/to/auto-complete"))
(add-to-list 'load-path ac-path)
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories (concat ac-path "ac-dict"))
(ac-config-default))
It works fine with C major mode, but doesn't turn on automatically when I open ObjC files. I can still turn it on manually and it will work fine along with the ObjC major mode.
Here's a snippet from the docs regarding ObjC major mode:
The hook `c-mode-common-hook' is run with no args
at mode initialization, then `objc-mode-hook'.
If I understand correctly, auto-complete adds a hook to the c-mode-common-hook, but objc-mode-hook somehow overrides it. Is there a way to fix this?
Thanks.
While looking through the source code of auto-complete.el, I've stumbled upon this definition
(defcustom ac-modes
'(emacs-lisp-mode
lisp-interaction-mode
c-mode cc-mode c++-mode
java-mode clojure-mode scala-mode
scheme-mode
ocaml-mode tuareg-mode
perl-mode cperl-mode python-mode ruby-mode
ecmascript-mode javascript-mode js-mode js2-mode php-mode css-mode
makefile-mode sh-mode fortran-mode f90-mode ada-mode
xml-mode sgml-mode)
"Major modes `auto-complete-mode' can run on."
:type '(repeat symbol)
:group 'auto-complete)
It turns out that auto-complete doesn't have a true global mode. It is enabled only with those major modes that are included in the ac-modes variable.
So, adding the following line to the .emacs file has solved the issue for me.
; add this line after the auto-complete mode has been loaded
(add-to-list 'ac-modes 'objc-mode)
Use the following:
(defun my-objc-mode-hook ()
(auto-complete-mode 1))
(add-hook 'objc-mode-hook 'my-objc-mode-hook)
Note 1: The function auto-complete-mode is a toggle function, when called with no arguments.
Note 2: It's possible to add an anonymous function using lambda, but this have several drawbacks. The most important ones are: modifying the function and reevaluating the expression will add the modified function in addition to the earlier version and C-h v xxx will print the full unformatted lambda function, which typically is hopeless to read and understand.
(add-hook 'objc-mode-hook 'auto-complete-mode)
That should do it if you're using auto-complete-mode. You can add more complex things to mode hooks by doing:
(add-hook 'objc-mode-hook '(lambda ()
(something-with arguments)))
Note that both arguments to add-hook are quoted, this is necessary and if you add unquoted functions they will probably not work.