I use flymake in Emacs to check code written in several languages. However, I can't see any way to use flymake on elisp itself.
I'm aware of elint-current-buffer, and byte-compile-file, which both give useful warnings about undefined variables etc. Oddly, they don't always give the same errors: for example, elint doesn't warn about (require 'cl). I've also tried auto-compile-mode (available on MELPA) but this still writes the warnings to a separate buffer.
I would really like my elisp code to be underlined when I make mistakes, as I type. How do I do this? I've configured flymake before, but that was with external programs, not Emacs itself.
The Emacs wiki has this to say about flymake for emacs lisp, though it doesn't seem very complete.
flycheck supports Emacs Lisp "out of the box", though.
Erefactor is pretty decent, and available from the wiki as well as melpa: http://www.emacswiki.org/emacs/erefactor.el
I also like to run checkdoc post-save:
(defun emagician/run-checkdoc ()
"run checkdoc on save if it is an elisp file"
(if (and (eq major-mode 'emacs-lisp-mode)
(> (length buffer-file-name)
(length package-user-dir))
(not (string= (concat package-user-dir "/")
(substring buffer-file-name 0 (+ 1 (length package-user-dir))))))
(checkdoc)))
(add-hook 'after-save-hook 'emagician/run-checkdoc)
Now there is elisp-flymake-byte-compile backend for flymake built in.
To enable add this to config:
(add-hook 'emacs-lisp-mode-hook #'flymake-mode)
Related
I often use rgrep to find files I need to change and then a macro to go through these files, do the change and save it. It's a very neat flow with one downside: I have prettier check each file on save and flycheck (using eslint) also goes absolutely crazy and maxes out my CPU.
So I wondered, if there is any good way to globally (as my macro visits a lot of files) disable temporarily (as I want these modes after the macro finished) certain modes, most importantly flycheck?
I didn't find anything related, any ideas on how this could be done?
EDIT:
This is how I load flycheck e.g. in rjsx-mode:
;; disable jshint since we prefer eslint checking
(setq-default flycheck-disabled-checkers
(append flycheck-disabled-checkers
'(javascript-jshint)))
;; disable json-jsonlist checking for json files
(setq-default flycheck-disabled-checkers
(append flycheck-disabled-checkers
'(json-jsonlist)))
;; use eslint with web-mode for jsx files
(defun my/use-eslint-from-node-modules ()
(let* ((root (locate-dominating-file
(or (buffer-file-name) default-directory)
"node_modules"))
(eslint (and root
(expand-file-name "node_modules/eslint/bin/eslint.js"
root))))
(when (and eslint (file-executable-p eslint))
(setq-local flycheck-javascript-eslint-executable eslint))))
(add-hook 'flycheck-mode-hook #'my/use-eslint-from-node-modules)
(flycheck-add-mode 'javascript-eslint 'rjsx-mode)
(Full emacs config here: https://github.com/phuhl/sheeshmacs)
Thx
Try changing your macro to open files with find-file-literally. This will always open files in Fundamental mode, preventing flycheck from running (well, assuming you have no flycheck hooks for Fundamental mode.)
See C-h f find-file-literally or Visiting in the Emacs manual.
I'm using swank-clojure from https://github.com/technomancy/swank-clojure.
I'd like to run clojure-jack-in automatically when a clojure file is opened in emacs. All my projects use lein, so it should always be appropriate.
Presumably you should check that it hasn't been called already. Something like this in ~/.emacs.d/init.el seems to work, but is there a downside or a better way to achieve the same effect?
(defun clojure-jack-in-once ()
"clojure-jack-in if it hasn't been run already,
as indicated by presence of *swank* buffer"
(if (eq nil (get-buffer "*swank*"))
(clojure-jack-in)))
(add-hook 'clojure-mode-hook 'clojure-jack-in-once)
You might want to extend that to check the liveness of the process, using process-status and get-buffer-process, but there is no fundamental reason you can't do that.
A slightly nicer bit of elisp would be:
(unless (get-buffer "*swank*")
(clojure-jack-in))
Adding the check:
(let ((proc (get-buffer-process "*swank*")))
(unless (and proc (eq (process-status proc) 'run))
(clojure-jack-in)))
That should check if the process is still running and automatically restart if required.
(slime-connected-p) is what you're looking for.
Or (and (featurep 'slime) (slime-connected-p)) to be safe.
I use two emacs (Aquamcs and text based emacs) on my Mac.
I normally use text based emacs for just editing something, so I don't want to load anything with it.
What I came up with is to have the checking code in .emacs to exit/break if it's text based emacs (darwin system but not aquamacs).
(when (and (equal system-type 'darwin) (not (boundp 'aquamacs-version)))
(exit) ??? (break) ????
)
It seems to work, but I don't know how to break out of .emacs. How to do that?
ADDED
I just wanted to speed up in loading text based emacs on my mac, and I thought about breaking out as a solution. Based on the helpful answers, I came up with the following code that runs .emacs only when it's not a text based emacs.
(setq inhibit-splash-screen t)
(unless (null window-system)
I don't know of any way to do exactly what you want. Some workarounds:
You can stop the evaluation of your .emacs by evaluating (error "message") but that's a bit unpleasant.
You can re-order your .emacs so that there's a (unless (CONDITION) ...) around the whole of the file.
You can run emacs -Q FILE when you're at the command line.
Why do you want to do this? Are you concerned at the time it takes to load your .emacs? If so, you might consider using the Emacs client/server instead.
I am not sure how to exit as well but..... I would rather advice another kind of logic for your init file than a flat file with all different configurations.
Take for example your ~/.emacs (or better ~/.emacs.d/init.el) as your controller and files like ~/.emacs.d/aquamacs.el or ~/.emacs.d/textmode.el as your individual configuration files.
That would make your init having something like this :
(defun my-short-hostname()
(string-match "[0-9A-Za-z]+" system-name)
(substring system-name (match-beginning 0) (match-end 0))
)
;Load different config file in text mode or gui mode.
(if (null window-system)
(load-file "~/.emacs.d/texmode-emacs.el")
(load-file "~/.emacs.d/gui.el"))
;Load configuration for this host only, ie ~/.emacs.d/myhostname.el if exist
(if (file-exists-p
(downcase (concat "~/.emacs.d/" (my-short-hostname) ".el")))
(load-file (downcase "~/.emacs.d/" (my-short-hostname) ".el"))))
I suggest having specific, different files to load conditionally from your .emacs, one for one setup, another for another setup.
Alternatively, just wrap the code for each setup in a progn and do the conditional in place, in .emacs itself.
I am aware of Speedbar (I prefer the structure in the same frame as the rest of my work), and dired shows too much information. I'm after something like the svn-status tree representation. Is there anything like that?
Thank you.
EDIT: Here's what I found the most intuitive:
I am using Speedbar with the following hack from here. I had to use the commented "try this" part, FYI.
(require 'speedbar)
(defconst my-speedbar-buffer-name "SPEEDBAR")
; (defconst my-speedbar-buffer-name " SPEEDBAR") ; try this if you get "Wrong type argument: stringp, nil"
(defun my-speedbar-no-separate-frame ()
(interactive)
(when (not (buffer-live-p speedbar-buffer))
(setq speedbar-buffer (get-buffer-create my-speedbar-buffer-name)
speedbar-frame (selected-frame)
dframe-attached-frame (selected-frame)
speedbar-select-frame-method 'attached
speedbar-verbosity-level 0
speedbar-last-selected-file nil)
(set-buffer speedbar-buffer)
(speedbar-mode)
(speedbar-reconfigure-keymaps)
(speedbar-update-contents)
(speedbar-set-timer 1)
(make-local-hook 'kill-buffer-hook)
(add-hook 'kill-buffer-hook
(lambda () (when (eq (current-buffer) speedbar-buffer)
(setq speedbar-frame nil
dframe-attached-frame nil
speedbar-buffer nil)
(speedbar-set-timer nil)))))
(set-window-buffer (selected-window)
(get-buffer my-speedbar-buffer-name)))
So I wanted to just print a tree quickly and all Emacs based solutions seemed either rather old or massive like (ECB/CEDET) which I don't know enough about, so for quick fix I did
sudo apt-get install tree
then from dired buffer
M-! tree --dirsfirst RET
voilĂ ! directory tree without any specific libs, as an added bonus using tree -f outputs tree with full paths, making it obvious to jump to file with C-x C-f directly from the tree output buffer.
There is a tree extension for emacs mode Sunrise Commander. Sunrise Commander is like Midnight Commander.
There's the Emacs Code Browser. Last I heard using it with a current emacs may be tricky or difficult because it makes use of some tools that were recently integrated into Emacs via CEDET.
I'd recommend NeoTree. It's easy to install and easy to use.
I would like to make a gradual switch from GNU Emacs to Xemacs. Are there tricks I can use to have the two play well?
Currently, I see the following issues:
xemacs alters .emacs
The two do not like each others .elc files.
Thanks!
Interesting, most appear to be moving in the other direction as I believe XEmacs to be fairly dormant (based on activity of the xemacs-announce list). Simple packages can co-exist, but many folks have given up making their packages work in both XEmacs and Emacs.
But, in answer to your question, to get your .emacs to work in both, I'd start writing a some routines to do function translation between the two. For example, at one point I needed this to get my .emacs to work in XEmacs:
(if (not (fboundp 'tags-table-files))
(defun tags-table-files ()
(tag-table-files tags-file-name)))
Other things were triggered on the Emacs variant, which I stored in a variable GNU:
(setq GNU (not (string-match "XEmacs\\|Lucid" (emacs-version))))
(if GNU
(do-emacs-thing)
(do-xemacs-thing))
I was keeping compiled .emacs files and did this:
(setq compiled-dot-emacs-name (format ".emacs-%d%s" emacs-major-version
(if GNU "" "X")))
Regarding compiled packages, I'd probably store all the .el files in one directory (say emacs-lisp), but have an xemacs variant (xemacs-lisp) with symlinks to the .el files. And then you just byte compile each directory from the appropriate Emacs variant, and make sure to have your load-path point to the right one.
The Emacs wiki has a page on Emacs versus XEmacs which might be a good starting point to figure out other tips to make them cohabitate. Specifically, there's a page for customizing both.
I don't use xemacs, but newer GNU emacs will check for .emacs.d/init.el as well, so maybe moving .emacs stuff to init.el makes sense. Additionally you can link it to .xemacs/init.el if you manage to keep your customization applicable for both.
There is also a discussion on what emacs to prefer on emacswiki.
I started a slow move from Xemacs to Emacs a while ago. I now use both on a daily basis. To make the transition smoother (one set of init files), I stole the following .emacs file from http://xemacs.seanm.ca/_emacs (but the link is now dead).
(setq user-init-file
(expand-file-name "init.el"
(expand-file-name ".xemacs" "~")))
(setq custom-file
(expand-file-name "custom.el"
(expand-file-name ".xemacs" "~")))
(if (file-exists-p user-init-file)
(load-file user-init-file))
(if (file-exists-p custom-file)
(load-file custom-file))
My ~/.xemacs/init.el starts off with:
(unless (boundp 'running-xemacs)
(defvar running-xemacs nil))
(setq load-path (cons "~/.elisp" load-path)) ; packages for both emacsen
(if running-xemacs
(setq load-path (cons "~/.elisp/xemacs" load-path)) ; packages for Xemacs only
(setq load-path (cons "~/.elisp/gnuemacs" load-path))) ; packages for Gnuemacs only
From then on it is pretty obvious what I have (the occasional (if running-xemacs) ...). I also deleted all the .elc files from ~/.elisp, but I presume that Trey Jackson's suggestion will work.
on modern systems i do not see the need for precompiled elisp files anymore. The benefit in looking and on the fly changing the .el-files is much more higher.
.emacs: put your own defines in .emacs_startup (or which name you prefere) and put all your gnu-enmacs stuff there and put a conditional load in your .emacs