How to save customized variable to a given file? - emacs

By default, emacs saves all customized variables to .emacs file. Yet I want to save it in a separate file for easy management. Is there any way to configure this behavior in Emacs 24

Try this:
(setq custom-file "~/.emacs-custom.el")

Related

How to disable Emacs Lisp auto-reformatting?

I absolutely despise that Emacs automatically reformats my init.el file. Every time I use the GUI to change a setting, when I look back at my init.el file, Emacs has warped all of the formatting I've done on the file (e.g. changing the indentation, moving things onto their own lines, etc.).
How do I disable this functionality?
Your choice is to either avoid the customize GUI altogether (I am not
even sure that is possible because, e.g.,
packages
use them), or put something like this in your .emacs:
(custom-set-variables
`(custom-file ,(expand-file-name "custom.el" user-emacs-directory)))
(when (file-readable-p custom-file)
(message "ignoring and deleting `%s'!" custom-file)
(delete-file custom-file))
This will make Emacs write all its custom forms to a file that you
never load and delete whenever you start Emacs.
This also means that you will have to manually move all your
customizations from custom-file to your .emacs yourself.

How to open an org-mode file automatically in Emacs

How to open files automatically when starting emacs? does not work either under Windows or under Linux.
After adding the find-file command I received a message
so I disabled the auto-save, but the file does not load anyway.
(add-to-list 'load-path "~/emacs/org-8.0.3")
(setq auto-save-default nil)
(find-file "/home/uwe/Dropbox/orgmode.org")
You probably want to set the initial-buffer-choice variable so that it switches to your org file after running your init.el.
(setq
org-default-notes-file "/home/uwe/Dropbox/orgmode.org"
initial-buffer-choice org-default-notes-file)
The message you see proves that the file is indeed loaded just fine. All it tells you is that there's some auto-save file left over, indicating that some edits were not saved last time. You can ignore the message (which is not an error message), or you can use M-x recover-this-file RET to recover the unsaved changes from the auto-save file.
I strongly recommend you don't disable auto-saving.
IOW what you think doesn't work (automatically loading orgmode.org) actually does work. The only thing that doesn't work the way you want is that this file is not displayed and instead the *scratch* buffer is displayed. The reason for this depends on how you started Emacs. And the fix for it depends on all the different ways you might start Emacs (e.g. if you only ever start Emacs in the exact same way, it's easier).
Don't disable the auto-save, it could save ours files.
Anyway, delete #orgmode.org, if the diff between the two file don't interest you.

How can I save my Emacs settings?

I am using the Emacs editor, and every time I start Emacs, I lose my previous settings.
For example, every time I have to type:
M-x cua-mode RET
M-x auto-complete-mode RET
How can I save my settings in Emacs?
Thanks.
You can add them to your .emacs file.
(cua-mode)
(auto-complete-mode)
If you find that there are already things in your .emacs file, then you might want to add the commands at the end.
The best answer I can think of is to point you at the manual:
http://www.gnu.org/software/emacs/manual/html_node/emacs/Customization.html
In particular, see the sections on "Easy Customization" and the "Init File"; but I would recommend at least skimming over everything in this section.
In your emacs directory there is a site-lisp folder. Normally it will be empty. you could create a file default.el in this folder. Add these two lines
(cua-mode t)
(auto-complete-mode)
and save it.This will be executed during Init. If you want to set environment variables for your emacs application only(not permanent) add a file called site-start.el in the site-lisp directory and define value for that variable ex:(setenv "VARIABLENAME" "value"). The site-lisp directory is in the standard search path for Lisp library.

load-path and load a lisp file

after setting a path for my lisp files in emacs in the .emacs file, like this
(add-to-list 'load-path "~/elisp/")
logically I should also use a load command for a specific file I guess what is that command
I tried
(load-file-name "google-c-style") with the .el added also for the file, what should be the right way to do this
however no success.
It's just (load), not (load-file-name).
If the .el has a line like (provide 'google-c-style), then all you need in your .emacs is:
(require 'google-c-style)
load-file-name is a variable which holds the full name of the file loaded by 'load'
use C-h-v load-file-name to read the documentation
Now, to load a file use the function 'load' - This looks for elisp source or binaries in the loaded paths
Eg: (load "google-c-style.el")
Note: There are another functions 'load-file'and 'load-library which work slightly differently. Read more about these here: http://www.gnu.org/software/emacs/manual/html_node/emacs/Lisp-Libraries.html#Lisp-Libraries
Also, as mentioned in one of the answers one can also use the provide - require feature.
Read this post to learn more about the differences between these functions(load, load-file, require, autoload)
http://ergoemacs.org/emacs/elisp_library_system.html

Setup for emacs org-mode outside .emacs file

I would like to set up a project to be published as HTML using org-mode.
I don't want to litter my .emacs with project definitions, and I was wondering where I could put the (setq org-publish-project-alist) variable.
Can I somehow put it in the same dir?
Ryan McGeary describes what I think is a good way to organize emacs startup files.
Update:
The domain emacsblog.org expired :(
You can look at the cached copy of the originally linked page.
You could just add a new file in your .emacs.d (or whereever) and do a load-file in your .emacs file.
-- EDIT --
For example, you could have the following in your .emacs
(load (expand-file-name "~/.emacs.d/lisp/personal-org-mode-stuff.el"))
and then put all of your customization stuff in ~/.emacs.d/lisp/personal-org-mode-stuff.el and it will load that file and import all of your .emacs
Another poster also posted a link to a description of how to add your lisp files to the load path and require them.
If you don't set it manually at all, but rather use Emacs' customize mechanism to control the value of this variable, your .emacs file will not be cluttered if you add the following two lines to your .emacs:
(setq custom-file "~/.emacs-custom.el")
(load custom-file 'noerror)
Although some might claim that it's kind of ironic that you have to add two lines two your .emacs file to declutter it that way...