How dow I configure Org Mode elisp link dialog? - emacs

I have written an org-mode model of a Mac keyboard which uses links to identify elisp functions associated with a given key and optional modifier. It occurred to me that I could use the org-mode external elisp link type so that when I click on the text, the code will execute to describe the key binding (describe-function). And it works, but with a nasty side effect that I get prompted with an ugly dialog to approve executing the code. I totally understand that this is default behavior but I am hoping this behavior can be easily overridden by an org-mode configuration setting so that "yes" is effectively always selected. Perhaps the answer is to create a custom protocol.

I think what you need to set are:
;; enable prompt-free code running
(setq org-confirm-babel-evaluate nil ;; for running code blocks
org-confirm-elisp-link-function nil ;; for elisp links
org-confirm-shell-link-function nil) ;; for shell links

Related

Is it possible to have a specific org-mode file use a custom theme or face?

I would like to be able to specify a theme or set of custom faces that are specific to a file that will be opened in org-mode. Is there any way I can do that? I already have https://github.com/vic/color-theme-buffer-local but that doesn't provide a way to automatically apply it when a specific file opens.
An ideal solution would not involve hardcoding in my init.el, but would involve setting a variable or calling elisp in the loaded file (or a referenced setupfile).
For an example of why this would be useful, some files are very flat, and are more readable with one set of styles, and other files are deeply nested, and benefit from another set of styles.
The original poster has cited a particular library called color-theme-buffer-local ( https://github.com/vic/color-theme-buffer-local ), which the original poster wants to apply to a file opened in the major-mode known as org-mode -- only if a certain variable is t.
The following example uses the code cited in the instructions for color-theme-buffer-local by calling the line of code: (load-theme-buffer-local 'misterioso (current-buffer)) The variable my-favorite-variable will control when the previous line of code is called when opening an org-mode buffer -- i.e., when non-nil it applies, when nil it does not apply.
EDIT (November 16, 2014):  The following is a revised answer based upon the desire of the original poster to use file-local variables:
https://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html#Specifying-File-Variables
http://www.gnu.org/software/emacs/manual/html_node/elisp/File-Local-Variables.html#File-Local-Variables
The behavior described by the original poster in the comment underneath this answer is due to the fact that the regular org-mode-hook is run before the file-local variables are taken into consideration. Therefore, the variable my-favorite-variable was still nil when the org-mode-hook ran its course (using the initial answer). The following revised answer uses the hack-local-variables-hook, which runs after the file-local variables are taken into consideration.
(defvar my-favorite-variable nil)
(defun my-favorite-function ()
(interactive)
(when
(with-current-buffer (current-buffer)
my-favorite-variable)
(load-theme-buffer-local 'misterioso (current-buffer))))
(add-hook 'hack-local-variables-hook 'my-favorite-function)
To my knowledge, color themes are global, for the whole Emacs session running. The same applies for background color which I'd like dark for shell buffers, and light otherwise; not possible ATM.
If you like light backgrounds, you can have a look at my color theme "Leuven" (in Emacs 24.4, in MELPA or on GitHub) and report improvements you'd find useful.

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.

How do I get a list of all the currently available commands and hotkeys?

To help me learn to work with various emacs modes, I would like to have a second monitor with a little HTML page that is used for showing me what sorts of things I can type or key-chord on whatever I'm currently looking at in emacs.
So how can I get a list of all the commands or key-chords available to me in my current mode?
Someone else will no doubt tell you how to get a cheatsheet such as you request (well, here is info about that too).
But if you want something that tells you dynamically what keys are available in the current context, no matter what it is, then this is what I have to offer:
C-h m tells you about the current (major) mode. C-h b tells you about currently available keys.
The Icicles feature key completion gives you access to all of the currently available key sequences, via key S-TAB. If you use a prefix key first, then S-TAB, then you see all the completions of that prefix key. You can move up and down the key hierarchy, including even menu items, to see all possible keys. You can use C-M-RET to get help (info about) any given key that is available. Here is some more about this feature of showing you all currently possible key bindings.
I would very much like to know good answer to this question myself! At present I am using this simple function to display key bindings for the current major mode in *Help on keys* buffer:
(defun describe-current-bindings (mode)
"Show key bindings for the current major mode in *Help on keys* buffer."
(interactive)
(with-current-buffer (get-buffer-create "*Help on keys*")
(erase-buffer)
(insert (documentation mode))))
And then use defadvice to call the function automatically whenever I switch buffers or windows:
(defadvice switch-to-buffer (after display-keys-buffer activate)
(describe-current-bindings major-mode))
(defadvice select-window (after display-keys-window activate)
(describe-current-bindings major-mode))
Now I can open *Help on keys* buffer in another frame and move that frame to my second monitor.
If you use other functions to switch windows (from windmove package, etc) you may need to add defadvice for them as well.
Try the pacakge help-fns+.el, there are some useful functions: describe-mode - "Display documentation of current major mode and minor modes.", describe-keymap - "Describe bindings in KEYMAP, a variable whose value is a keymap.", etc. For example,
(describe-keymap 'global-map) ;; global bindings
(describe-keymap 'emacs-lisp-mode-map) ;; major mode bindings
(describe-keymap 'smartparens-mode-map) ;; minor mode bindings

Can I change emacs settings while it's running?

I'm very new to the Emacs text editor and have just started customizing my ~/.emacs file. I'm wondering if it's possible to change an Emacs setting while it's running. For example, if I put the following in my ~/.emacs file:
(show-paren-mode 1)
I can do the same thing when Emacs is running by typing:
M-x then scroll-step then 1.
Why doesn't this work when I want to do something like this:
(setq scroll-step 1)
When I type:
M-x then setq,
all I get is (no match). There must something I'm not understanding here.
There is a few things:
yes, you can change settings at run-time. If you edit your .emacs file, put your cursor after the closing parenthesis in:
(show-paren-mode 1)
And hit ctrl-x ctrl-e and it will evaluate the code.
some things and variables (though very few) require them to run special things after the setting was changed. Generally there aren't too many and most variables you set will take effect immediately after doing the steps in #1.
However, if you edit your settings using M-x customize you'll find that when you make changes there it'll make the settings active immediately, even in those special cases where something special needs to be done after a value change.
M-x allows you to run "interactive" commands. Some elisp functions are supposed to be called directly by the end user, and others are really only meant when writing elisp into a file. And M-x only lets you easily do the ones that have been marked "interactive". Though M-shift-: will let you type an expression and see the results. EG, try M-shift-: followed by (1+ 2) at the prompt.

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.