latex-electric-env-pair-mode in AUCTeX - emacs

the guys of the plain tex-mode have added a very nice feature with emacs 24.1, a minor mode called latex-electric-env-pair-mode which keeps existing \begin{...} [...] \end{...} pairs matched. I.e. when changing the environment name in the \begin{...} tag, its corresponding \end{...} is changed automatically (very nice when changing from starred to non-starred version of an environment and vice-versa).
However, when comparing with AUCTeX, the tex-mode still sucks... but I really like the new minor mode. I have tried to make a stand-alone minor mode by copying everything that looked like it was used from tex-mode.el to a new file and changed all the descriptors (so they won't conflict with AUCTeX or any remainders for tex-mode). Unfortunately this won't work, the minor mode can be turned on but it is broke: nothing is happening.
I'm not a (e)lisp programmer, that is to say I don't really understand the code. But maybe someone likes the feature of this minor mode and can port it to a stand-alone version?
Also there might be some package out there which provides similar/equal functionality?
I'd appreciate any help!

You probably missed tex-env-mark (which sets marks that are used later by latex-electric-env-pair-mode to find environment starters/enders) or latex-syntax-propertize-rules (which runs tex-env-marks on relevant parts of the buffer) or the setting of syntax-propertize-function (which uses latex-syntax-propertize-rules so that these rules are actually used).
BTW, rather than copying those things, I recommend you try something like the untested code below:
(defconst my-latex-syntax-propertize-function
(with-temp-buffer (latex-mode) syntax-propertize-function))
(add-hook 'LaTeX-mode-hook
(lambda ()
(set (make-local-variable 'syntax-propertize-function)
my-latex-syntax-propertize-function)
(latex-electric-env-pair-mode 1)))

Related

org mode with clojure - can't get export to work

EDIT I've also asked this question on emacs.stackexchange
I'm a relative emacs newbie and have set up my emacs (24.4.1) to work with clojure as described here.
The gist of it is that I am now using the latest org-mode from git and loading it in my init.el (I am using prelude btw) as below:
(add-to-list 'load-path "~/repos/org-mode/lisp")
(require 'org)
(require 'ob-clojure)
I am trying to use org to write a literate clojure program that I can export to markdown. Clojure and babel now work well, evaluation works etc, but when I try to export my org file I get an error.
load-with-code-conversion: Symbol's value as variable is void: p
The stack trace when I set toggle-debug-on-error is:
Debugger entered--Lisp error: (void-variable p)
eval-buffer(#<buffer *load*> nil
"/Users/krisfoster/repos/org-mode/lisp/ox.el" nil t)
; Reading at buffer position 229233
load-with-code-conversion("/Users/krisfoster/repos/org-mode/lisp/ox.el"
"/Users/krisfoster/repos/org-mode/lisp/ox.el" nil t)
autoload-do-load((autoload "ox" "Export dispatcher for Org mode.\n
\nIt provides an access to common export related tasks in a
buffer.\nIts interface comes in two flavors: standard and
expert.\n\nWhile both share the same set of bindings, only the
former\ndisplays the valid keys associations in a dedicated
buffer.\nScrolling (resp. line-wise motion) in this buffer is done
with\nSPC and DEL (resp. C-n and C-p) keys.\n\nSet variable `org-
export-dispatch-use-expert-ui' to switch to one\nflavor or the
other.\n\nWhen ARG is \\[universal-argument], repeat the last
export action, with the same set\nof options used back then, on
the current buffer.\n\nWhen ARG is \\[universal-argument] \\
[universal-argument], display the asynchronous export
stack.\n\n(fn &optional ARG)" t nil) org-export-dispatch)
command-execute(org-export-dispatch)
I tried to resolve this by (require-ing the various org export packages, the ones in the clone of the org git repo that is, from within my init.el. But no dice - in fact that generated yet more issues. I have tried debugging but can't figure out what is wrong. I am suspecting I need to be requiring something but don't know what.
I have my init.el here - init.el gist
Any-one have any ideas what I am doing wrong?
Thanks in advance.
There was a bug in org-mode around the time you made this post, so the problem may be resolved. However, I noticed a few issues with your init file. Some things which might help
Use the lisp package manager to install your packages (ELPA). This will make your life much easier. The org guys maintain an ELPA repository which is updated regularly and will likely be a little more stable than just pulling in the repo. They have a version called org-plus-contrib which I use and find quite good. Just add
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/"))
You state that your running prelude, but I can't see anything in your init which is loading prelude (only a call to a function which turns off the guru-mode). Prelude is pretty good and quite popular, but if your going to use it, you need to 'drink the cool aid' that is, do things in the prelude way. For example, prelude comes with org-mode and uses ELPA to install it. You need to be careful your not get a blend of org versions. Another alternative to prelude which I found very good is Steve Purcell's emacs.d. I found it a little easier to work with YMMV, but it may be worth checking out as it has good support for the mac. See emacs.d
It is a really good idea to break up your emacs init script into separate files. This makes it easy to comment out lots of stuff when your trying to track down a problem and allows you to just focus on the key bits your trying to get working. I maintain my init.el file as an org file and use babel to generate all the lisp code. You can have a look at it on github. I originally started with Purcell's emacs.d and then borrowed with pride (stole) much of it to go into my own config. It isn't a fine example of how to configure emacs, but might help with your setup
I notice your attempting to use cider as the backend 'evaluator' for clojure code. Note that you only need to do this if you want to have blocks of clojure in your org file which you want to evaluate and then use the result. You don't need to do this if all you want to do is generate *.clj files from your org code. Instead, you just want to 'tangle' your org file, which will generate the updated clj source files, which you can then work on. This keeps things a lot simpler and avoids problems arising when you try to do things with your org file that attempt to evaluate the clojure code and fail. Note also that I expect you would need to do a bit more than just set cider as the backend evaluator - cide is just an interface to a repl. You would need a repl as well.

emacs doremi: to change color-themes

I'm trying to get doremi working in emacs. Specifically, at this stage, to allow me to quickly scroll through a condensed list of color-themes and see each theme as I go through it. For this I would use the 'M-x doremi-color-themes+' command.
What I've done:
Installed color-themes (successfull)
Installed doremi.el, doremi-cmd.el, ring+.el and added
(add-to-list 'loadpath "~/elisp/themes")
(add-to-list 'loadpath "~/elisp/doremi/")
(require 'color-theme)
(color-theme-initialize)
(color-theme-classic)
;; create a list of color themes to scroll through using 'doremi-cmd
(setq my-color-themes (list 'color-theme-classic
'color-theme-retro-green
'color-theme-gray30
'color-theme-subtle-hacker
'color-theme-jonadabian-slate))
(require 'doremi)
(require 'doremi-cmd)
(require 'ring+)
to the .emacs file.
What emacs does:
When I type the comand 'M-x doremi-color-themes+' into the mini-buffer it seems to accept that I've given it a valid command and tells me to use the and arrow keys to move through the list. But when I do that all that happens is the cursor moves up and down in the active window. No changing of color-themes.
Being somewhat new to emacs (and especially customising it) I'm sure I have missed a step or put something in the wrong place. Perhaps there's some sort of (setq 'bla-bla-bla (...)) I need to do?
Sorry for your trouble. Please state your Emacs version (M-x emacs-version), and your version of color-theme.el.
You do not need to require library ring+.el if you use Emacs 23 or later (its code was included in GnuEmacs 23.)
You do not need to use (color-theme-initialize) or (color-theme-classic). The former is done automatically by doremi-color-themes+.
Try starting from emacs -Q (i.e., no init file, ~/.emacs), to be sure there is no interference from stuff in your init file.
Your variable my-color-themes is not referenced anywhere. Instead of defining that variable, just customize user option doremi-color-themes. (Or leave its value nil, which means that all color themes will be cycled through.)
Feel free to contact me by email if you continue to have a problem. Or continue here, if you prefer.
[Just to be sure: you are using color-theme.el, right? There is a lot of confusion out there between Emacs "custom themes" and color themes. Do Re Mi supports both, but they are different critters.]
After a bit for back and forth with #Drew we found a solution to the problem.
It turned out the major problem was that I was using emacs in 'terminal mode' rather than as a GUI application. Bare in mind I'm using a mac.
In the context of Terminal, my arrow keys send escape sequences and so doremi cannot read the event as intended. So it just escapes and applies the message to the active buffer.
There is an answer.
By adding the following lines to my .emacs file (or whatever your init file for emacs is) I was able to redirect doremi to use two other keys. ie. not the up and down arrows.
(setq doremi-down-keys '(?n))
(setq doremi-up-keys '(?p))
Doing this tells doremi to use 'n' as the down key and 'p' as the up key. And all works just fine.
Because I am only new to the world of programming and computing I may often use incorrect terminology. If this is the case please let me know and I will edit accordingly for clarity and consistency.

What happened to the ido-imenu in ruby-mode function in Emacs24?

Emacs 23.2 in emacs-starter-kit v1 has C-x C-i (or ido-imenu) (similar to Sublime Text's Cmd+R). Emacs24 in emacs-starter-kit v2 lacks this function. I found this github issue and a fix, which try to recreate the functionality. While this ido-imenu works in elisp-mode, it stopped working in ruby-mode. I get:
imenu--make-index-alist: No items suitable for an index found in this buffer
Has anyone figured out how to get this to work?
Why was this taken out of Emacs24?
Is there a new replacement for this function?
Since the function is part of ESK (as opposed to something budled with Emacs) you'd probably do best to report the bug upstream. On a related note ESK main competitor Emacs Prelude offers the same functionality (bound to C-c i by default) and it seems to be working fine with ruby-mode in Emacs 24. Here you can find more on ido-imenu.
So I finally figured it out, after reading the Defining an Imenu Menu for a Mode section on emacs-wiki again.
Short answer: you need to add this bit to your customization. Feel free to add more types to the list (I am happy with just methods).
(add-hook 'ruby-mode-hook
(lambda ()
(set (make-local-variable imenu-generic-expression)
'(("Methods" "^\\( *\\(def\\) +.+\\)" 1)
))))
Longer answer: I first tried to define a ruby-imenu-generic-expression function and set that to imenu-generic-expression by using the ruby-mode-hook:
(defvar ruby-imenu-generic-expression
'(("Methods" "^\\( *\\(def\\) +.+\\)" 1))
"The imenu regex to parse an outline of the ruby file")
(defun ruby-set-imenu-generic-expression ()
(make-local-variable 'imenu-generic-expression)
(make-local-variable 'imenu-create-index-function)
(setq imenu-create-index-function 'imenu-default-create-index-function)
(setq imenu-generic-expression ruby-imenu-generic-expression))
(add-hook 'ruby-mode-hook 'ruby-set-imenu-generic-expression)
This however did not work (I would get the same error as before). More reading of the Defining an Imenu Menu for a Mode section showed me the way. Now, I'm not an elisp expert, so here's my hypothesis: basically, the above method works for modes where the
major mode supports a buffer local copy of the “real” variable, ‘imenu-generic-expression’. If your mode doesn’t do it, you will have to rely on a hook.
The example for foo-mode made it clear how to do it for ruby-mode. So it appears that ruby-mode does not have a buffer-local copy of the real imenu-generic-expression variable. I still can't explain why it worked in Emacs 23.2 (with ESK v1) but does not on Emacs24, but hey at least I found a working solution.

Entering a minor mode with a major mode in Emacs

This question may be a duplicate of this question, but I can't get the following to work properly in my emacs.
I am trying to enter minor mode mlint-mode whenever I enter major mode matlab-mode (both modes available at their SourceForge page). I have the following in my .emacs file:
(add-hook 'matlab-mode-hook
(function (lambda()
(mlint-mode))))
which looks like the answer to the question I linked above. When opening a .m file, I get the following error:
File mode specification error: (void-function mlint-mode)
Could someone please assist in helping me write the correct hook to enter mlint-mode when I open a .m file? FWIW, I'm running emacs 23.1.50.1.
I think the correct name is mlint-minor-mode. Also, remember to ensure that all matlab stuff is known by Emacs, this can be done using:
(require 'matlab-load)
As a side note, it is typically a bad idea to use lambda functions in hooks. If you inspect the value of the hook you will see a lot of unrelated things. Also, if you modify your lambda expression and re-add it, both the old and the new version will be on the hook.
Instead, you can do something like:
(defun my-matlab-hook ()
(mlint-minor-mode 1))
(add-hook 'matlab-mode-hook 'my-matlab-hook)
The "1" is ensures that mlint mode is turned on or stay on if enabled earlier.

Updating font-lock keywords in emacs without major mode reload

I am doing small modification to SLIME, so that I can get all currently loaded symbols from Lisp, analyze them and make font-lock fontify them.
I managed to do all these steps, but I have a small problem - when keyword list changes in font-lock the buffer is not updated unless you restart the major lisp-mode. I don't want to restart lisp-mode every time I update keywords, because I have several hooks on lisp-mode that I want to run only when I load the file for the first time.
Is there an other way to update font-lock so it reads all then new keywords and fontifies the buffer accordingly? Switching off font-lock and using font-lock-fontify-buffer does not do the trick.
UPD: Added bounty - the question is still up. I need a way to reload font-lock keyword without reloading major mode.
Ok, how about this instead:
(defun my-font-lock-restart ()
(interactive)
(setq font-lock-mode-major-mode nil)
(font-lock-fontify-buffer))
You could temporarily clear the mode hook variable and restart it:
(defun my-restart-lisp-mode ()
(interactive)
(let ((lisp-mode-hook nil))
(normal-mode)))
Triggering the major-mode is not what makes font-lock do its thing. I am not intimately familiar with the internals of SLIME or lisp-mode, but just setting the variable should make it work. Toggling font-lock-mode will make font-lock start refontifying with the new keywords in mind, as should font-lock-fontify-buffer.
I hack on cperl-mode, mostly, and it is a simple matter of cperl-init-faces (which sets the internal font-lock variables) and a restart of font-lock. lisp-mode should not be much different, except for not needing a call to cperl-init-faces ;)
Edit: some experimentation with lisp-interaction-mode reveals that even restarting font-lock-mode is not strictly necessary. Just changing font-lock-keywords is enough, as long as you re-trigger fontification somehow. (Editing text, font-lock-fontify-buffer, etc.)