Emacs: Gloabally disable flycheck/prettier temporarily - emacs

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.

Related

What is the difference of tex-mode and latex-mode and LaTeX-mode in emacs

I am configuring AUCTeX in emacs.
Most of the configurations are put in a LaTeX-mode-hook. When I open a main.tex file, I notice that the major mode is latex-mode and my hooked configurations are not activated. I have to M-x Tex-latex-mode to activate them. But the major-mode is still latex-mode.
(add-hook 'LaTeX-mode-hook
(lambda ()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; auctex
(setq TeX-auto-save t)
(setq TeX-parse-self t)
))
So I would like to know what is the difference of these modes and how can I turn on AUCTeX automatically when I open a *.tex file.
The modes provided by AUCTeX are listed at https://www.gnu.org/software/auctex/manual/auctex.html#Modes-and-Hooks and they are
plain-TeX-mode
LaTeX-mode
ams-TeX-mode
ConTeXt-mode
Texinfo-mode
docTeX-mode
Instead,
tex-mode
plain-tex-mode
latex-mode
slitex-mode
doctex-mode
(note the different capitalization) are the major modes provided by the TeX mode package shipped with Emacs.
If you want to open all *.tex files with AUCTeX LaTeX mode add this to your .emacs:
(add-to-list 'auto-mode-alist '("\\.tex$" . LaTeX-mode))
Actually, this shouldn't be necessary, because AUCTeX defines the tex-mode.el mode names as alias of its own modes.
TLDR: Use latex-mode or LaTeX-mode (they mean the same thing), no need to change auto-mode-alist, and use LaTeX-mode-hook for hooking into AucTeX.
Setting up AucTeX can be quite confusing, because it uses advice to override Emacs' built-in support for TeX and friends.
So, after installing AucTeX from ELPA, you should see the following in C-h f latex-mode:
This function has :override advice: ‘TeX-latex-mode’.
Same for all the other tex modes, though the list of modes that AucTeX overrides depends on the value of the TeX-modes variable.
The function LaTeX-mode is not defined in AucTeX (any more?): it's defined in core Emacs, with a cryptic comment about compatibility:
;; The following three autoloaded aliases appear to conflict with
;; AUCTeX. However, even though AUCTeX uses the mixed case variants
;; for all mode relevant variables and hooks, the invocation function
;; and setting of `major-mode' themselves need to be lowercase for
;; AUCTeX to provide a fully functional user-level replacement. So
;; these aliases should remain as they are, in particular since AUCTeX
;; users are likely to use them.
;; Note from Stef: I don't understand the above explanation, the only
;; justification I can find to keep those confusing aliases is for those
;; users who may have files annotated with -*- LaTeX -*- (e.g. because they
;; received them from someone using AUCTeX).
;;;###autoload
(defalias 'TeX-mode #'tex-mode)
;;;###autoload
(defalias 'plain-TeX-mode #'plain-tex-mode)
;;;###autoload
(defalias 'LaTeX-mode #'latex-mode)
What this all means is that, at least in 2021, you do not need to change auto-mode-alist to use AucTeX; just installing it is enough for it to override Emacs' builtin functionality.
Unfortunately, there's one last source of confusion. Even though LaTeX-mode is now mostly just a useless alias for latex-mode, it turns out that code in AucTeX that overrides latex-mode does not call latex-mode-hook (it calls LaTeX-mode-hook, which is different. So the LaTeX- variables, which are the AucTeX ones (as opposed to the lowercase ones that are builtin with Emacs), are still useful.

Is there a flymake mode for Elisp itself?

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)

Emacs fixme mode on javascript

I just got fixme-mode.el, and loaded it. It works just fine on C, Lisp and other languages. But it doesn't work on Javascript.
(defcustom fixme-modes '(erlang-mode java-mode c-mode emacs-lisp-mode jde-mode
scheme-mode python-mode ruby-mode cperl-mode
slime-mode common-lisp-mode c++-mode d-mode
js2-mode haskell-mode tuareg-mode lua-mode
pascal-mode fortran-mode prolog-mode asm-mode
csharp-mode sml-mode javascript-mode html-mode)
"The modes which fixme should apply to"
:group 'fixme-mode)
I even added javascript-mode and html-mode to the list, but it still doesn't work.
Is there a way I can make it work for all modes? Is there like an "emacs-mode" that includes all others? If not, why isn't it working on .js files?
Thank you!
if you are emacs emacs inbuilt javascript mode (I guess you are using that) that is js-mode not javascript-mode
add this .emacs file(~/.emacs.d/init.el)
(add-to-list 'fixme-modes 'js-mode)
Generally you don't edit defcustom directly in the source code. .emacs is the one for your customizations
UPDATE:
To make fixme-mode to be available for all buffers we should define a global-minor-mode
(defun turn-on-fixme-mode ()
(fixme-mode 1))
(define-global-minor-mode global-fixme-mode
fixme-mode turn-on-fixme-mode
:group 'fixme-mode)
now call global-fixme-mode

emacs23 / elisp: how to properly autoload this library?

I am upgrading to emacs23. I find that my emacs.el loads much more slowly.
It's my own fault really... I have a lot of stuff in there.
So I am also trying to autoload everything possible that is currently "required" by my emacs.el.
I have a module that exposes 12 entry points - interactive functions I can call.
Is the correct approach to have 12 calls to autoload in order to insure that the module is loaded regardless of which function I call? Are there any problems with this approach? Will it present performance issues?
If not that approach, then what?
What you really want is to get the autoloads generated for you automatically, so that your .emacs file remains pristine. Most packages have the ;;;###autoload lines in them already, and if not, you can easily add them.
To manage this, you can put all the packages in a directory, say ~/emacs/lisp, and in there have a file named update-auto-loads.el which contains:
;; put this path into the load-path automatically
;;;###autoload
(progn
(setq load-path (cons (file-name-directory load-file-name) load-path)))
;;;###autoload
(defun update-autoloads-in-package-area (&optional file)
"Update autoloads for files in the diretory containing this file."
(interactive)
(let ((base (file-truename
(file-name-directory
(symbol-file 'update-autoloads-in-package-area 'defun)))))
(require 'autoload) ;ironic, i know
(let ((generated-autoload-file (concat base "loaddefs.el")))
(when (not (file-exists-p generated-autoload-file))
(with-current-buffer (find-file-noselect generated-autoload-file)
(insert ";;") ;; create the file with non-zero size to appease autoload
(save-buffer)))
(cd base)
(if file
(update-file-autoloads file)
(update-autoloads-from-directories base)))))
;;;###autoload
(defun update-autoloads-for-file-in-package-area (file)
(interactive "f")
(update-autoloads-in-package-area file))
If you add 'update-autoloads-in-package-area to your kill-emacs-hook, then the loaddefs.el will automatically be updated every time you exit Emacs.
And, to tie it all together, add this to your .emacs:
(load-file "~/emacs/lisp/loaddefs.el")
Now, when you download a new package, just save it in the ~/emacs/lisp directory, update the loaddefs via M-x update-autoloads-in-package-area (or exit emacs), and it'll be available the next time you run Emacs. No more changes to your .emacs to load things.
See this question for other alternatives to speeding up Emacs startup: How can I make Emacs start-up faster?
Well, who cares how slowly it starts?
Fire it up via emacs --daemon & and then connect using either one of
emacsclient -c /some/file.ext, or
emacsclient -nw
I created aliases for both these as emx and emt, respectively. Continuing once editing session is so much saner...
Ideally you shouldn't have any load or require in your .emacs file.
You should be using autoload instead...
e.g.
(autoload 'slime-selector "slime" t)
You will need to use eval-after-load to do any library specific config, but the upshot is that you won't need to wait for all this to load up front, or cause errors on versions of Emacs that don't have the same functionality. (e.g. Terminal based, or a different platform etc.)
While this may not affect you right now, chances are, in future you will want to use the same config on all machines / environments where you use Emacs, so it's a very good thing to have your config ready to fly.
Also use (start-server) and open external files into Emacs using emacsclient - So you avoid restarting Emacs.

What are good practices to get GNU emacs and xemacs co-habitate

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