custom-set-variables add blank space on subsequent uses - emacs

I followed the emacs haskell tutorial, and couldn't understand some of its language regarding the use of custom-set-variables in the text quoted below. It seems that custom-set-variables should be used in one way on first usage, and another way (with added blank space) on subsequent uses.
My questions are:
What exactly should the second usage be?
Why is it that custom-set-variables should be used differently on first and subsequent usage?
Thanks
-- quoted code --
To enable it, add
(custom-set-variables '(haskell-process-type 'cabal-repl))
to your personal configuration file. However, if your personal configuration file already has a custom-set-variables command, you'll need to instead add a blank space and then '(haskell-process-type 'cabal-repl) before its closing parenthesis.

It's just saying that you can include multiple custom variables in one invocation of custom-set-variables. So if you already have
(custom-set-variables
'(some-variable 'some-value))
you can add to it like so:
(custom-set-variables
'(some-variable 'some-value)
'(haskell-process-type 'cabal-repl))

Related

Is there a way to disable indentation for one specific org-mode src block at a time?

I'm using most of the standard features of org-mode that come with the spacemacs develop branch, but I haven't been able to find a way to disable the automatic indentation for source code blocks on a case by case basis. I use tangle and I'm writing Dockerfile's in the same file that I'm writing groovy code or javascript for example. The Dockerfile's are the only ones I want not to be indented so I can get syntax highlighting. Here's what it looks like without the indentation:
And here's what it looks like with the indentation that automatically happens if I edit the text:
The automatic indentation is fine for groovy for example, so I have no issue with the automatic indentation here. (in fact, if I still got the syntax highlighting for Dockerfile's I probably wouldn't mind too much except the weird word wrapping not respecting the background face). Here's the example with groovy:
As you can see, I tried a :noindent property I found in the org-mode docs that's usually in a #+STARTUP directive. I also searched stack overflow, but I didn't find anything fruitful that didn't disable indenting for all source blocks or for the entire file.
In my practice (I'm not sure it is a good practice or not, just share it to you):
I setup org-src-tab-acts-natively to true for using the language’s major-mode indentation. In your case, it will format the src block with the formatting rules of dockerfile-mode.
I created a new major-mode plain-mode for the content which should not be indented automatically. Personally, I use this mode for something like:
shell outputs
ASCII diagrams
...
#+begin_src plain
this will not
be
auto
indented
#+end_src
Above src block will not be indented when you select them as region, and TAB on them.
In this way, the src blocks will always behavior as expected when formatting them.
Aside, the example code of plain-mode:
(define-derived-mode plain-mode
clean-mode "Plain"
"Major mode for plain text."
;; preserve the auto indentation on line
(setq-local indent-line-function 'indent-relative)
;; disable auto indentation on region
(setq-local indent-region-function (lambda (start end))))

Set emacs comment style based on file extension

There are multiple questions along these lines but I haven't been able to find what I need from start to finish. I have been using emacs for a few years but am not used to its customization.
I have a unique file type, identified by its extension, which emacs is not configured for. Its comment style is
<!-- text -->
and I would like to set the variables comment-start and comment-end to the relevant values (which I am assuming will allow me to use comment-region). I don't know the correct way to do this so that it will always be configured when I open this file type but won't affect the default behavior of emacs.
Do I need to make a new major mode for this file type, and then set the variables, or is there an easier way of doing it? An example of the complete requirements for my .emacs file would be much appreciated!
See here. I think this will work:
(add-to-list 'auto-mode-alist
'("\\.extension\\'" . (lambda ()
(setq-local comment-start "<!--")
(setq-local comment-end "-->"))))
Alternatively, if this file extension is well known (or if these files are close enough to a well known syntax), you may be able to just find a major-mode online that does what you want. For example, NXML Mode may just give you the comment syntax you want along with some other useful features.

Debugging "Error setting nil" in Elisp

I have this piece of Elisp code in my Emacs configuration file:
(when (string= (getenv "TERM") "screen")
(custom-set-variables
(custom-set-faces
'(font-lock-comment-face ((((class color)
(min-colors 8)
(background dark))
(foreground red)))))))
When I start Emacs I get Error setting nil: (setting-constant nil) from this code. Though it seems to work fine I'm aware that this might be a sign of some hidden problem. I don't know Elisp too well thus I need help. Can anyone offer an explanation of this error and tell me how to eliminate it? I'm using Emacs 24.3.1
There's quite a lot wrong with that, I'm afraid.
custom-set-faces and custom-set-variables are two separate forms; you shouldn't be calling one inside the other.
You shouldn't be wrapping a call to either of those functions in a conditional expression. Both forms are generated and updated automatically when you use the customize interface, and Emacs won't find them if they're not top-level forms in your init file. Which means it will create an additional copy of each one when it needs to. Which leads to...
You mustn't have multiple instances of these forms. In fact Emacs includes the following warning comments when it generates the form:
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
Right now you are encouraging that situation to occur.

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.