Here is my flymake setup in .emacs file:
(when (load "flymake" t)
(defun flymake-pyflakes-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "pyflakes" (list local-file))))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.py\\'" flymake-pyflakes-init)))
(add-hook 'find-file-hook 'flymake-find-file-hook)
(load-library "flymake-cursor")
I want to use flymake only for .py files. and disable it for the rest. but It is always enabled.
For example when I open an html file I always get following error
Error (flymake): Flymake: Failed to launch syntax check process 'xml' with args (val /home/huseyin/vipsatis/templates/cancellation/base_flymake.html): Searching for program: no such file or directory, xml. Flymake will be switched OFF
So I want to turn it off for anything but py files. is it possible?
(
For the people having the same problem, I want to explain the error message: Flymake uses xmlstarlet for xml and html validation. And it tries to call it as "xml val ......" but it has to call it as "xmlstarlet val...." to fix this you have to find flymake.el file and change the xml call with xmlstarlet.
)
Remove the HTML entry from the list:
(delete '("\\.html?\\'" flymake-xml-init) flymake-allowed-file-name-masks)
OK I got it. here is what I did:
first of all I found flymake.el file.(If you dont have it you probably have flymake.elc file under emacs installation.In that case just copy flymake.el file under your load path so it will be used instead of compiled version(.elc file) under insallation).
than I found following function and commented .xml and .html bindings.
(defcustom flymake-allowed-file-name-masks
'(("\\.\\(?:c\\(?:pp\\|xx\\|\\+\\+\\)?\\|CC\\)\\'" flymake-simple-make-init)
;("\\.xml\\'" flymake-xml-init)
;("\\.html?\\'" flymake-xml-init)
("\\.cs\\'" flymake-simple-make-init)
("\\.p[ml]\\'" flymake-perl-init)
("\\.php[345]?\\'" flymake-php-init)
("\\.h\\'" flymake-master-make-header-init flymake-master-cleanup)
("\\.java\\'" flymake-simple-make-java-init flymake-simple-java-cleanup)
("[0-9]+\\.tex\\'" flymake-master-tex-init flymake-master-cleanup)
("\\.tex\\'" flymake-simple-tex-init)
("\\.idl\\'" flymake-simple-make-init)
;; ("\\.cpp\\'" 1)
;; ("\\.java\\'" 3)
;; ("\\.h\\'" 2 ("\\.cpp\\'" "\\.c\\'")
;; ("[ \t]*#[ \t]*include[ \t]*\"\\([\w0-9/\\_\.]*[/\\]*\\)\\(%s\\)\"" 1 2))
;; ("\\.idl\\'" 1)
;; ("\\.odl\\'" 1)
;; ("[0-9]+\\.tex\\'" 2 ("\\.tex\\'")
;; ("[ \t]*\\input[ \t]*{\\(.*\\)\\(%s\\)}" 1 2 ))
;; ("\\.tex\\'" 1)
)
Other comment outed lines was already there. Now flymake does not work for html and xml files
In the error message you receive it's telling that it can't find the command-line XML validation tool xml. You can fix it by installing a compatible XML validation tool (xmllint is the right choice I guess).
But if you really just want to disable Flymake for HTML and XML files you don't have to copy whole the flymake.el file and change it. Simply add this line your init file:
(defun flymake-xml-init ())
This overrides the function that Flymake calls for HTML and XML files with an empty function.
Customize the variable named flymake-allowed-file-name-masks.
You can do it like this too:
M-x customize-variable RET
flymake-allowed-file-name-masks RET
Related
I want to export my org files to HTML files to certain directory when save.
I can use Emacs and Org-mode but I don't know Elisp.
With Org-Mode 8.3 and Emacs 24.5.1 the accepted answer creates a pseudo-buffer *Org HTML Export* that you have to save manually, while the key C-c C-e h h more conveniently saves the file directly.
To really auto-export in the background try the following code:
# Local variables:
# eval: (add-hook 'after-save-hook 'org-html-export-to-html t t)
# end:
You can combine this solution with the following function in your .emacs:
(defun toggle-html-export-on-save ()
"Enable or disable export HTML when saving current buffer."
(interactive)
(when (not (eq major-mode 'org-mode))
(error "Not an org-mode file!"))
(if (memq 'org-html-export-to-html after-save-hook)
(progn (remove-hook 'after-save-hook 'org-html-export-to-html t)
(message "Disabled org html export on save"))
(add-hook 'after-save-hook 'org-html-export-to-html nil t)
(set-buffer-modified-p t)
(message "Enabled org html export on save")))
Note: The below was written for Emacs 23. Check the answer by #AndreasSpindler for an up-to-date solution.
Emacs has a couple of hooks which are called in certain events. The hook you are looking for is probably the after-save-hook. Just set it to the function you want to run every time you save the file. In your case this would be org-html-export-to-html.
There are many ways to do this, but the following method is probably the fastest and doesn't involve any "real" elisp. Put the following lines somewhere in your org file:
# Local variables:
# after-save-hook: org-html-export-to-html
# end:
The next time you open that file, you'll get a warning and be asked if the local variable should be set (as that's potentially unsafe, but not a problem here). Press y and everything should just work.
The command for this is
C-c C-e h h (org-html-export-to-html)
Export as an HTML file. For an Org file myfile.org, the HTML file will be myfile.html. The file will be overwritten without warning. C-c C-e h o Export as an HTML file and immediately open it with a browser.
Reference
I've got "Cannot open load file" error at (require 'org-mime) while load-path variable seems to be all right:
load-path is a variable defined in `C source code'.
Its value is
("/home/alexey/.emacs.d/elpa/bbdb-20130526.1945" "/home/alexey/.emacs.d/elpa/org-mime-20120112" "/home/alexey/.emacs.d/elpa/smex-20130421.2153" "/usr/share/emacs/24.3/site-lisp" "/usr/share/emacs/site-lisp" "/usr/share/emacs/24.3/lisp
...
Curiously, the remedy looks like this (.emacs):
(add-to-list 'load-path "~/.emacs.d/elpa/org-mime-20120112")
It isn't merely ugly: it's dysfunctional, because the versioned path is subject to change. But why the error?
There is an interesting issue that happens when you load a file that requires another file -- the file that is required must be loaded in chronological order before the next file. For example, if B requires A then A must be placed higher up in chronological order so that when B loads, A is already loaded.
I've had really good luck with this type of setup. Most files end with el or elc, so I'm not sure why you want to load a file with a different or no extension, but it is certainly possible to do that if you want.
(let* ((root.d "~/") (sub-dir (concat root.d ".emacs.d/")))
(load-file (concat sub-dir "init.el"))
(setq load-path
(append `(,root.d ,sub-dir
,(concat sub-dir "elpa/yasnippet")
) load-path)))
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.)
I recently started using django-html-mumamo-mode which is part of nXhtml in emacs and everything seems to work except that when I start writing javascript code in an html page, I get the warning/error
Can't find library /usr/share/emacs/23.2/lisp/progmodes/js.el
I checked in that folder and all of the files have the .elc extension including js.elc, which is probably why emacs can't find it. Can I change something to make emacs just load the .elc file?
Edit: This continues to occur if I run M-x load-library js or M-x load-library js.elc
Edit2: I have confirmed that load-suffixes is set to ("el" "elc"), and that js.elc is in the progmodes folder, which is in load-path and that all users have read permissions for that file. I am using emacs version 23.2.1, and when I set debug-on-error to t I got a traceback, and it looks like the following part contains the error:
error("Can't find library %s" "/usr/share/emacs/23.2/lisp/progmodes/js.el")
find-library-name("/usr/share/emacs/23.2/lisp/progmodes/js.el")
find-function-search-for-symbol(js-indent-line nil "/usr/share/emacs/23.2/lisp/progmodes/js.elc")
(let* ((lib ...) (where ...) (buf ...) (pos ...)) (with-current-buffer buf (let ... ... ... ...)) (put fun (quote mumamo-evaled) t))
(if (get fun (quote mumamo-evaled)) nil (let* (... ... ... ...) (with-current-buffer buf ...) (put fun ... t)))
(unless (get fun (quote mumamo-evaled)) (let* (... ... ... ...) (with-current-buffer buf ...) (put fun ... t)))
(progn (unless (get fun ...) (let* ... ... ...)))
(if mumamo-stop-widen (progn (unless ... ...)))
(when mumamo-stop-widen (unless (get fun ...) (let* ... ... ...)))
Notably, the third line contains a reference to the correct file, but it ends up trying to load the wrong one. Has anyone seen this kind of thing before or have any idea how to fix it?
If you read the section in the Emacs manual on "How Programs Do Loading, the js.elc file should be loaded if normal library -loading commands (e.g. - "require", "autoload", "load-file", etc) are being used. Some things to do to debug this:
Does your userid have system security permissions to access the js.el file in that location?
If you type M-x emacs-version, what version of Emacs are you running?
The "load-library" command searches for lisp files in the "load-path". When you examine the contents of your load-path, is the specified directory in it?
Set the variable "debug-on-error" to "t" and re-attempt to write javascript code in an html page - when the error occurs, check the source line where the error occurs and, if it's not apparent from that what is causing the problem, post an update to your question with a few lines of the source where the error occurred as well as the stack trace that was produced by Emacs.
EDIT: Ok, now that you've added the stack trace, it's possible to see why the error is occurring. Here are the key lines from the "find-function-search-for-symbol" function (which is the function where the error is occurring in):
(when (string-match "\\.el\\(c\\)\\'" library)
(setq library (substring library 0 (match-beginning 1))))
;; Strip extension from .emacs.el to make sure symbol is searched in
;; .emacs too.
(when (string-match "\\.emacs\\(.el\\)" library)
(setq library (substring library 0 (match-beginning 1))))
(let* ((filename (find-library-name library))
In line#2, the function is setting the library name equal to the "*.elc" library name minus the "c" (e.g. it's converting it from "/usr/share/emacs/23.2/lisp/progmodes/js.elc" to "/usr/share/emacs/23.2/lisp/progmodes/js.el". Then, in line#7 of the above code, it's trying to find that source member (and failing as it doesn't exist). Looking further at the stack trace, the key line is:
(if (get fun (quote mumamo-evaled)) nil (let* (... ... ... ...) (with-current-buffer buf ...) (put fun ... t)))
which is called in the nXhtml "mumamo-funcall-evaled" function. The author of nXhtml obviously has not considered that the ".elc" file may exist but that the ".el" is not in the same directory. It appears that he used to distribute js.el with nXhtml but stopped doing so since it is now shipped with most recent Emacs distributions. So, in his environment, he probably has the ".el" files in the same directory as the ".elc" files and hasn't encountered this problem.So, you should probably do 2 things:
Notify the author of the nXhtml library so that he can fix the bug in his code.
Copy the necessary ".el" source files to "/usr/share/emacs/23.2/lisp/progmodes/" so that you don't get the error. Alternatively, you may choose to re-install js.el (and possibly some other modules) in another directory and put that directory ahead of "/usr/share/emacs/23.2/lisp/progmodes/" in your "load-path".
Doing #1 will get the problem fixed in the long-term while doing #2 should let you use nXhtml in the short-term.
Check your value of load-suffixes
C-h v load-suffixes. You probably want this to be something like (".elc" ".el"). If it is make sure that your mode hasn't set it to something weird, or bound it dynamically.
I would like emacs to mark files that are generated as read-only when they're opened. The part of the puzzle that I'm missing is how to check if a file "exists". I currently have the following:
;;
;; get file extension
;;
(defun get-ext (file-name)
(car (cdr (split-string file-name "\\."))))
;;
;; get the base name of the file
;;
(defun base-name (file-name)
(car (split-string file-name "\\.")))
;;
;; if an 'lzz' file exists for this header, mark it as read only
;;
(defun mark-read-only ()
(if (string= (get-ext (cur-file)) "h")
(if ( ??file-exists??? (concat (base-name (cur-file)) ".lzz") )
(toggle-read-only))))
What can I use for "???file-exists???"?
Once I find this, I'll add "mark-read-only" to the appropriate hook (which I think is the find-file-hook).
BACKGROUND
We use lzz as a code generator to simplify our C/C++ development process. Briefly, lzz takes a single input file (which looks very like C/C++) and generates header and source files as appropriate.
By default, lzz includes #line directives so that the debugger points to the original source and not the generated source, however, to reduce compilation dependencies we normally disable these directives in header files. The result is that when debugging templates or inline functions, the debugger normally points to the generated header file and not the original source file.
This is not a big deal, however, recently I've found that when debugging I'll make a quick modification to the displayed file and then I'll rebuild. Of course this normally means that the change I made disappears because the file I edited is generated and so the changes are "blown away" during the library rebuild.
SOLUTION
Thanks to everyone for their help and comments. A special thanks to cobbal for pointing out the correct function to use.
Here's the resulting code (with updates based on the other comments here too):
(defun cur-file ()
"Return the filename (without directory) of the current buffer"
(file-name-nondirectory (buffer-file-name (current-buffer)))
)
(defun mark-generated-as-read-only ()
"Mark generated source files as read only.
Mark generated files (lzz or gz) read only to avoid accidental updates."
(if
(or (string= (file-name-extension (cur-file)) "h")
(string= (file-name-extension (cur-file)) "cpp"))
(cond
(
(file-exists-p (concat (file-name-sans-extension (cur-file)) ".lzz"))
(toggle-read-only))
(
(file-exists-p (concat (file-name-sans-extension (cur-file)) ".gz") )
(toggle-read-only))
)
)
)
try file-exists-p
"Return t if file filename exists (whether or not you can read it.)".
Note that it's not spesific to files and works for directories too.
Depending on what you need, you might want file-readable-p instead of file-exists-p.
Apropos will only get you so far. Icicles provides apropos completion and progressive completion which let you find help easily for command, function, variable, etc. names that match subparts in an arbitrary order (is it file-exists-p or exists-file-p?).
Use f.el, modern library for file and directory manipulation. You can use f-exists?, f-file?, f-directory? and many other predicates. The library is better than standard functions, because it's every file related function you'll ever need under one namespace.