How to make Emacs C source directory permanent? - emacs

I'm new to Emacs and I'm just learning how to use it. I know how to set my "Emacs C Source dir" but I don't know how to make this change permanent. I guess I have to set it in my .emacs file but I don't know what is the command for it. Can someone help?

Ordinarily most user-settable variables can be edited with Customize, but for some reason the source-directory variable isn't one of them.
You will need to edit your ~/.emacs file to include a line such as:
(setq source-directory "/path/to/emacs/source/dir")
Do not include the trailing src directory; it will be added automatically. Then exit and restart Emacs.
Note that setting this after Emacs is running may have no effect because it's only read when find-func.el is loaded. You can set find-function-C-source-directory instead (with the /src), but that can get overwritten. It's better just to (setq source-directory ...) at startup, as above.

Assuming you have a decent locate-style shell-command, this saves you having to remember the path exactly. It should thus still work in your ~/.emacs.d/init.el if you upgrade to a newer version, as long as you still have the sources.
(setq source-directory
(file-name-directory
(shell-command-to-string
(concat "locate --limit 1 emacs-" emacs-version "/src"))))

Related

emacs can't find its things in its own load path

the following is output from a terminal session demonstrating that I, hopefully actually set this up right.
~ $cat .emacs
(require 'package)
(custom-set-variables
;;lots of comments generated by computer
'(package-archives (quote(("gnu" . "http://elpa.gnu.org/packages")
("marmalade" . "http://marmalade-repo.org/packages")
("melpa" . "http://melpa.milkbox.net/packages/")
("org" . "http://orgmode.org/elpa")))))
(custom-set-faces
;;again lots of comments added by the computer
)
(add-to-list 'load-path "/usr/share/emacs/24.3/site-lisp/mu4e")
~ $ ls /usr/share/emacs/24.3/site-lisp/mu43
#there are a lot of files here, but I am only going to show 2 right now
mu4e.elc
mu4e.el
... and yet emacs M-x mu4e returns [no match]. I have checked to load-path variable, and it is there. What am I doing wrong?
You need to add one more thing so that mu4e is loaded. There are two different ways to do this.
First, you could add (require 'mu4e) after you've added the path to your load-path. This will immediately load mu4e.
Alternatively, you could add the following:
(autoload 'mu4e "mu4e" "Launch mu4e and show the main window" t)
This will tell Emacs to load it lazily (i.e. not until you actually use it). Autoloading is documented here. (This is essentially done for you for packages installed via package.el - it's the same mechanism, you just don't need to specify it yourself).
The benefit of autoloads is that Emacs's initial startup is faster, since rather than loading every package right away it waits until you use them.

Let .emacs.d behaves just like a .d folder

I want to solve my “.emacs bankruptcy” issue, and I've gone through
https://help.ubuntu.com/community/EmacsHowto
http://www.emacswiki.org/emacs/DotEmacsBankruptcy
http://www.emacswiki.org/emacs/DotEmacsDotD
http://www.gnu.org/software/emacs/manual/html_node/emacs/Init-File.html
and it is still unclear to me whether the .emacs.d folder is the solution. I.e., whether it will behave just like a normal .d folder, e.g., /etc/profile.d/, where you drop you scripts and they will be picked up by the system auto-magically. Please confirm.
If not, can someone give me a script that does that, or give me a solution please?
Thanks
The essential content of my ~/.emacs file is:
(require 'cl)
(loop for src in (directory-files "~/.emacs.d" 'full-path "[0-9].*\\.el$") do
(let ((byte (concat src "c")))
(when (file-newer-than-file-p src byte)
(byte-compile-file src))
(message "Loading %s.elc" byte)
(load-file byte)))
It loads configuration files from ~/.emacs.d which start with a number. If the source file (extension .el) is newer than the byte-compiled version (extension .elc) then it byte-compiles the source. Afterwards it loads the byte compiled file.
Here's my ~/.emacs:
;; base dirs
(defvar dropbox.d "~/Dropbox/")
(defvar emacs.d (concat dropbox.d "source/site-lisp/"))
;; load path
(add-to-list 'load-path emacs.d)
(defun add-subdirs-to-load-path (dir)
(let ((default-directory dir))
(normal-top-level-add-subdirs-to-load-path)))
(add-subdirs-to-load-path emacs.d)
(load "init")
All my other scripts are loaded by ~/Dropbox/source/site-lisp/init.el
and are themselves located in ~/Dropbox/source/site-lisp.
That's how I have the same config on multiple machines.
And here's how .../site-lisp/hooks.el is loaded from init.el:
(load "hooks")
My init.el is about 100 lines, .emacs about 20 lines.
The rest 8000 lines of scripts are sliced into around 20 files.
~/.emacs.d/ does not work like /etc/profile.d/ or /etc/modules-load.d/ or similar directories, i.e. Emacs does not automatically load any Emacs Lisp file in this directory.
In fact, Emacs explicitly advises against placing Emacs Lisp libraries in ~/.emacs.d/. The byte compiler emits a warning if you add ~/.emacs.d/ to the load-path.
Instead, create a new sub-directory, e.g. ~/.emacs.d/lisp. Add this directory to your load-path explicitly, with the following code in init.el:
(add-to-list 'load-path (locate-user-emacs-file "lisp"))
Then, place your Emacs Lisp files in this directory, e.g. ~/.emacs.d/lisp/foo.el, and load them in your init.el:
(load "foo" nil 'no-message)
The best approach to avoid the dreaded .emacs bankruptcy is to actually avoid large customizations! Most notably, try to avoid any custom functions and commands.
Instead, try to a find an ELPA package that comes closest to what you want, and either try to get used to it, or customize it to your needs. If you don't find any, first try to write your own and distribute it on Github, Marmalade or MELPA.
Don't be afraid of maintaining a package in the public. You'll have to maintain your customization anyway, whether in your init.el or not, so you can just as well let other Emacs users help you with this job.
Adding code to your init.el should be your very last resort!

Emacs update-file-autoloads failing

I'm trying to setup emacs to be my GO IDE by following this tutorial with this code . I'm running into problems when I have to have emacs generate a file
From within Emacs, run M-x update-file-autoloads, point it at the go-mode.el file and tell it to generate a go-mode-load.el file.
I get this error when I enter the path of the file (location ~/.emacs.d/go-mode/go-mode.el)
Opening output file: no such file or directory, /build/buildd/emacs23-23.3+1/debian/build-x/lisp/loaddefs.el
I did a locate on this file and see I do have it but not at the path specified path above
$ locate loaddefs.el
/usr/share/emacs/23.3/lisp/loaddefs.el
...
If I had to guess I would say some kind of path problem. Do I have to set a path variable somewhere?
I installed emacs through apt-get install emacs23
I'm on Ubuntu 12.04
Thanks
EDIT
The process I'm doing to get the error.
M-x update-file-autoloads Enter
Update autoloads for file: ~/.emacs.d/go-mode/go-mode.el Enter
Opening output file: no such file or directory, /build/buildd/emacs23-23.3+1/debian/build-x/lisp/loaddefs.el
I had the same problem and finally got it working. Open your scratch buffer (or any other empty file) and type in the following two lines
(setq generated-autoload-file "~/.emacs.d/go-mode/go-mode-load.el")
(update-file-autoloads "~/.emacs.d/go-mode/go-mode.el")
Then evaluate both lines by putting the cursor at then of each line and type in C-x C-e to evaluate the line before the cursor. Do this for both lines. Then make sure to open go-mode-load.el and save the buffer - apparently emacs does not do this by default.
Once you've done this you can continue to follow the instructions at http://www.honnef.co/posts/2013/03/writing_go_in_emacs/
Disclaimer: I am sure there is a better way to do this and lisp experts will shriek at my answer. I have no clue about lisp and how to use lisp in emacs. I just did an informed guess :-)
Just recently hit this while attempting to get go-mode.el set up on my raspberry pi. Luckily, I had already generated a go-mode-load.el file successfully on my Mac and was able to take a look at that.
In there I saw this comment:
;; To update this file, evaluate the following form
;; (let ((generated-autoload-file buffer-file-name)) (update-file-autoloads "go-mode.el"))
So I cd'ed into the directory where I had downloaded go-mode.el, then touched a new file called go-mode-load.el, opened it up in emacs, pasted in that line of code, evaluated it with C-x C-e and it worked like a charm.
EDIT
Wasn't able to get the generated file working until I added these lines to the end. As of writing this I haven't taken the time to figure out why they are needed but adding them fixed the problem:
(provide 'go-mode-load)
;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; coding: utf-8
;; End:
;;; go-mode-load.el ends here
(Not an answer, but needs formatting)
Is there a local definition of `generated-autoload-file' in go-mode.el? If so, it will write there, so you need to remove that line.
;; update-file-autoloads docs
update-file-autoloads is an interactive compiled Lisp function in
`autoload.el'.
(update-file-autoloads FILE &optional SAVE-AFTER OUTFILE)
Update the autoloads for FILE.
If prefix arg SAVE-AFTER is non-nil, save the buffer too.
If FILE binds generated-autoload-file' as a file-local variable,
autoloads are written into that file. Otherwise, the autoloads
file is determined by OUTFILE. If called interactively, prompt
for OUTFILE; if called from Lisp with OUTFILE nil, use the
existing value ofgenerated-autoload-file'.
Return FILE if there was no autoload cookie in it, else nil.
Checkout the actual installation instructions from the go-mode-el GitHub webpage. It looks like there have been some changes which are not reflected in the tutorial.
Just try to either use ELPA or follow the manual instructions:
(add-to-list 'load-path "/place/where/you/put/it/")
(require 'go-mode-autoloads)

How to install a Emacs plugin (many times it's a .el file) on Windows platform?

I'm new to Emacs. I found many emacs plugins are released as an .el file. I'm not sure how to install them. Can I just put them in my emacs installation directory?
After placing it, say myplugin.el to your ~/.emacs.d/ directory, add the following in your .emacs file:
(add-to-list 'load-path "~/.emacs.d/")
(load "myplugin.el")
Also, in many cases you would need the following instead of the second line:
(require 'myplugin)
In any case, you should consult the documentation of the package you are trying to install on which one you should use.
If you are unsure where your ~ directory is, you may see it by typing C-x d ~/ and pressing Enter.
As already stated, you'll need the location of the file to be in Emacs' load path.
Read the comments at the top of the file to see if it has any particular installation or usage instructions. Authors often provide this information, and there isn't one single correct way to do it, so it's sensible to look.
Failing that, if the file contains a (provide 'some-name) line (typically at the end of the file), then you would be expected to use (require 'some-name) to load it.
You may also wish to byte-compile the library for speed (but that's a different question).
Many times, an emacs plugin will consist of a directory of elisp files that need to be accessible from the load path. A simple way to ensure that all individual elisp files as well as subdirectories of elisp files are included in the load path and accessible is to do something similar to the following:
Create a directory called ~/.emacs.d/site-lisp.
Install any single elisp files in the ~/.emacs.d/site-lisp directory.
Install any packages that consist of multiple elisp files in a subdirectory under your ~/.emacs.d/site-lisp directory.
Add the following code to your ~/.emacs file to ensure that Emacs "sees" all the elisp files that you have installed:
(add-to-list 'load-path "~/.emacs.d/site-lisp")
(progn (cd "~/.emacs.d/site-lisp")
(normal-top-level-add-subdirs-to-load-path))
This will ensure that all elisp files that are located either in either the ~/.emacs.d/site-lisp directory or in a subdirectory under that directory are accessible.
Some supplementary information:
MATLAB.el comes from http://matlab-emacs.sourceforge.net/
On windows, use the load path that looks like this:
(add-to-list 'load-path' "C:\\Dropbox\\Portable\\emacs\\matlab-emacs")
If you want FULL MATLAB functionality you should use:
;;MATLAB Mode:
(add-to-list 'load-path' "C:\\Dropbox\\Portable\\emacs\\matlab-emacs")
(require 'matlab-load)
if you just want to edit text files:
;;MATLAB Mode:
(add-to-list 'load-path' "C:\\Dropbox\\Portable\\emacs\\matlab-emacs")
(autoload 'matlab-mode "matlab" "Enter MATLAB mode." t)
(setq auto-mode-alist (cons '("\\.m\\'" . matlab-mode) auto-mode-alist))
(autoload 'matlab-shell "matlab" "Interactive MATLAB mode." t)

Platform-independent path (in LaTex and Elisp)?

I run Emacs on Win7 and Ubuntu and try to share most of my configuration via dropbox.com. I still could not figure out how to write the path to load-files or images (for example) in a platform independent way.
I mirrored my directory structure on both machines so that inside the home directory the relative path should work out. Is there a way to achieve this with a single path without if-clauses (if system ... else ...) everywhere?
I tried ~/ and it worked sometimes, sometimes not.
'home' is set on Win7, but it must be addressed as %home% on Win7 and as $HOME on ubuntu (right?).
I need a solution for:
elisp code
latex files (adress images, listings)
In Windows, ~ resolves to whatever the HOME environment variable is set to. I found it most useful to set HOME to C:\Users\username (in Win 7). This means I can put my .emacs file there, and also that ~ will reference files in it when I'm opening files.
Once you do this, your elisp can refer to ~ as your home directory on either Windows or Linux.
I have a setting at the top of my .emacs the tests the OS, and sets a CONST pointing to the the root directory of the path accordingly. Then, within the configurations, I just reference the variable within my path statements. Just tested on OS X and Windows 7.
Here's some examples:
(defconst HOME_DIR
(if (eq system-type 'darwin)
(concat "/Users/" (getenv "USER"))
(concat "c:/cygwin/home/" (getenv "USER")))
"Home directory. I could rely on the HOME environment variable,
but I'm being retentive.")
(defconst EMACS_PKGS (concat HOME_DIR "/emacs-pkgs")
"Directory for the emacs pkgs and configuration files.
Default uses `HOME_DIR' as a prefix")
;; isolate customize settings
(setq custom-file (concat EMACS_PKGS "/emacs-custom.el"))
My experience with Emacs on Windows is that ~ is not at C:\Users\yourusername. For me, it's in C:\Users\rafe\AppData\Roaming. So, for the case of Emacs, if you drop files in, say, %HOME%\AppData\Roaming (or, in Windows Emacs, ~), you'll have access to those files. That's where my .emacs was by default, at least. The path might be different on your system, so see where Emacs takes you when you try to find a file and type ~/.
That setting might be configurable, but I've never cared enough to change it.
As for LaTeX, sadly I can't help.
For LaTeX, see: “How to add an extra searchable dir with personal style files to TeXLive, NOT under ~/Library/texmf?” on the TeX SE. It might help.