I downloaded two .el files
One is to highlight current column where cursor is and another one to highlight some specific words.
I followed next steps in the file:
(add-to-list 'load-path "~/.xemacs/packages/") //path where I saved .el files
(load "column-marker") //name of file without .el extension
To this step it works fine, I find those when I press M-x column-marker and I can use it.
My problem begins when I want to use it everytime i open emacs and I found that I could use something similar to this:
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
Which in my case I am typing:
(add-to-list 'auto-mode-alist '("\\.\\'" . column-marker)) //I want to enable it for all .something files
But... when doing that, there is an error when opening emacs and it starts with default setup.
What am I doing wrong? I have tried many ways and none work.
Thanks in advance
Always post the error message you see. That helps others help you.
C-h f auto-mode-alist tells you that the functions you use in it must implement major modes. column-marker is not a major-mode function. It is not even a function; it is a file.
What you need to do, for each mode where you want some function in file column-marker.el to be invoked, is to put that function on the major-mode hook for that function. For example:
(add-hook 'emacs-lisp-mode (lambda () (interactive) (column-marker-1 80))
And lo and behold, what does the Commentary in file column-marker.el tell you?
;; Installation: Place this file on your load path, and put this in
;; your init file (`.emacs'):
;;
;; (require 'column-marker)
;;
;; Other init file suggestions (examples):
;;
;; ;; Highlight column 80 in foo mode.
;; (add-hook 'foo-mode-hook (lambda () (interactive) (column-marker-1 80)))
Couldn't be clearer. Provided you actually read it.
Seriously, a minimum of investigation is in order, before you post a question to StackOverflow. You should do a Google search, open README files and read them, and so on --- first. And in the case of Emacs questions, IMHO, you should ask Emacs first (e.g. C-h v auto-mode-alist).
According to the rules of S.O. posting, not doing preliminary simple research is even grounds for closing a question. So do not be surprised if this question gets closed or downvoted.
Related
My Emacs opens .m files in ObjC mode. However I want to open them in Octave mode. I have already added to the .emacs file:
(autoload 'octave-mode "octave-mod" nil t)
(setq auto-mode-alist (cons '("\\.m$" . octave-mode) auto-mode-alist))
What else should I do? I do have Octave mode installed.
Fortunately everything is working now and unfortunately I don't remember how I fixed it :) Maybe there was an error in my .emacs earlier. This is the more correct code:
(add-to-list 'auto-mode-alist '("\\.m$" . octave-mode))
Autoloading is unneeded in recent versions; if you do need to enable it, note that "octave-mode" is not a typo.
(autoload 'octave-mode "octave-mod" nil t)
Use this.
;; octave-mode
(autoload 'octave-mode "octave-mode" "Loding octave-mode" t)
(add-to-list 'auto-mode-alist '("\\.m\\'" . octave-mode))
Just ran into this exact problem.
Your statement is correct, but your .emacs file probably isn't loading up correctly. Emacs searches the "HOME" variable to load up preferences, lisp code etc.
To see what your HOME variable is:
Open scratch buffer (this is a "play place" to try things out):
C-x C-b *scratch* <RET>
Evaluate this expression by typing it, then putting the cursor to the right, then hitting C-x C-e
insert (getenv "HOME")
Emacs will display your home path at the bottom (mine defaulted to ...Documents and Settings\UserName)
I haven't worked out a good way to change it, but you're supposed to be able to simply add HOME as an environment variable (that didn't work for me).
It's also talked about a bit more over here:
http://www.gnu.org/software/emacs/manual/html_node/emacs/Windows-HOME.html
Also remember that the file has to be ".emacs" and not myConfig.emacs or something of the like. Use bash command ren to rename the file (windows explorer won't let you have nameless files)
My Emacs opens .m files in ObjC mode. However I want to open them in Octave mode. I have already added to the .emacs file:
(autoload 'octave-mode "octave-mod" nil t)
(setq auto-mode-alist (cons '("\\.m$" . octave-mode) auto-mode-alist))
What else should I do? I do have Octave mode installed.
Fortunately everything is working now and unfortunately I don't remember how I fixed it :) Maybe there was an error in my .emacs earlier. This is the more correct code:
(add-to-list 'auto-mode-alist '("\\.m$" . octave-mode))
Autoloading is unneeded in recent versions; if you do need to enable it, note that "octave-mode" is not a typo.
(autoload 'octave-mode "octave-mod" nil t)
Use this.
;; octave-mode
(autoload 'octave-mode "octave-mode" "Loding octave-mode" t)
(add-to-list 'auto-mode-alist '("\\.m\\'" . octave-mode))
Just ran into this exact problem.
Your statement is correct, but your .emacs file probably isn't loading up correctly. Emacs searches the "HOME" variable to load up preferences, lisp code etc.
To see what your HOME variable is:
Open scratch buffer (this is a "play place" to try things out):
C-x C-b *scratch* <RET>
Evaluate this expression by typing it, then putting the cursor to the right, then hitting C-x C-e
insert (getenv "HOME")
Emacs will display your home path at the bottom (mine defaulted to ...Documents and Settings\UserName)
I haven't worked out a good way to change it, but you're supposed to be able to simply add HOME as an environment variable (that didn't work for me).
It's also talked about a bit more over here:
http://www.gnu.org/software/emacs/manual/html_node/emacs/Windows-HOME.html
Also remember that the file has to be ".emacs" and not myConfig.emacs or something of the like. Use bash command ren to rename the file (windows explorer won't let you have nameless files)
I'm currently using tuareg-mode but I would like to be able to use the functionality of caml-mode as well. In particular I want to be able to use type annotations interactively, and apparently this occurs with caml-types. I tried putting http://cristal.inria.fr/~remy/poly/emacs/index.html in my .emacs.d, but I'm confused about how or if these two modes can work together. In fact, I can't get caml-mode to work at all.
I have this line in my init.el:
(add-to-list 'load-path "~/.emacs.d/modes/caml")
But the files are not loaded - at least, none of the function definitions or keybindings are. I really thought I was starting to grasp how these emacs plugins work, but I'm starting to wonder. Maybe someone can explain what else needs to happen?
Edit: I didn't realize I had to require 'caml for this to work. Still, annotations don't seem to be working although I have caml-types from http://caml.inria.fr/svn/ocaml/branches/gadts/emacs/. I compile with -annot but I'm still told there's no annotations file.
You can have type annotation with the tuareg mode.
If I have this exact ~/.emacs file:
(add-hook 'tuareg-mode-hook '(lambda ()
(define-key tuareg-mode-map [f10] 'caml-types-show-type); requires caml-types
))
(add-to-list 'auto-mode-alist '("\\.ml\\w?" . tuareg-mode))
(autoload 'caml-types-show-type "caml-types" "Show the type of expression or pattern at point." t)
then pressing F10 shows the type of the expression under the point.
As you know, you need to compile your file foo.ml with
ocamlc -annot foo.ml
so that there is a file foo.annot in the same directory as foo.ml.
In Emacs, I'd like to highlight the parts of long lines that exceed 80 characters.
The package highlight-80+ is great for that. But how can I automatically enable it when a C++ source file is loaded?
I tried to add highlight-80+ to the C++ mode, but it didn't work:
(require 'highlight-80+)
(defun my-c++-mode-common-hook ()
(highlight-80+-mode 1))
(add-hook 'c++-mode-common-hook 'my-c++-mode-common-hook)
When I load a .cc file it goes in C++ mode but highlight-80+ is not enabled, so the long lines are not marked.
Note that the Highlight80Plus wiki says that it is built-in to emacs starting with 23. I believe it's referring to whitespace-mode; it does this and is built in to emacs.
There is a function in emacs-starter-kit that does something like this already but you could easily duplicate it,
(defun esk-turn-on-whitespace ()
(whitespace-mode t))
(add-hook 'prog-mode-hook 'esk-turn-on-whitespace)
See the whitespace-mode, it does this kind of highlighting and more:
http://www.emacswiki.org/emacs/WhiteSpace
Can you try this:
(autoload 'highlight-80+)
(add-to-list 'auto-mode-alist '("\\.cpp$" . highlight-80+-mode))
EDIT: It turns out that the second edit to my .emacs file actually works. (See the comments below this entry.)
I tried a couple of addition to the .emacs to make all txt files opened in emacs use orgmode. They did not work. How can I make it happen?
;;SET EMACS AS DEFAULT MAJOR MODE TO FOR ALL FILES WITH AN UNSPECIFIED MODE
(setq default-major-mode 'org-mode)
;;OPEN ALL TXT FILES IN ORGMODE
(add-to-list 'auto-mode-alist '("\\.txt$" . org-mode))
Additionally:
It would be even better to open only txt files in a certain directory orgmode. Any hint as to how that could be done would also be appreciated.
Another way to do this is using directory-local variables. This is nice because you can put a file in any directory where you want this behavior to engage, and it works recursively in any subdirectories.
Create a file called .dir-locals.el in the desired directory.
Here are the contents:
((nil (eval . (if (string-match ".txt$" (buffer-file-name))(org-mode)))))
Read this like so: for any major-mode (nil), evaluate the following form:
(if .... (org-mode))
The regex in auto-mode-alist could be something more complex, like "^/path/to/.*\\.txt$"
You can implement a hook which verifies the file directory and modifies the buffer mode:
(add-hook 'find-file-hooks
(lambda ()
(let ((file (buffer-file-name)))
(when (and file (equal (file-name-directory file) "c:/temp/"))
(org-mode)))))
As an alternative you can add the mode line in the beginning of your text file. In this case emacs will set the specified mode.
; -*- mode: org;-*-
* header 1
** header 2
I glued together some code from Oleg Pavliv's answer here, and from yibe's at elisp - File extension hook in Emacs - Stack Overflow
(defun use-org-mode-for-dot-txt-files-in-owncloud ()
(when (and (string-match owncloud buffer-file-name)
(string-match "\\.txt\\'" buffer-file-name))
(org-mode)))
(add-hook 'find-file-hook 'use-org-mode-for-dot-txt-files-in-owncloud)
This way, though ownCloud Web and phone apps are currently friendly only with .txt files, from my PC I can use Emacs' Org-mode for them.
(If I set all .txt files to use Org-mode, it breaks todotxt-mode.)
(Note that owncloud is a string variable equal to my ownCloud path.)