.emacs, automake and cmake - emacs

A long time ago,when I wrote my .emacs setup[1], I used a shell script to compile and join the whole thing. The thing is now very old and "crusty", so I am now rewriting it to replace things such as:
(defmacro make-new-comment( mode face strcom color1 color2)
(list 'progn
`(make-face ',face)
`(if (not (assoc ,strcom ,(intern (concat (symbol-name mode) "-comments-alist"))))
(setf ,(intern (concat (symbol-name mode) "-comments-alist"))
(append ,(intern (concat (symbol-name mode) "-comments-alist")) '((,strcom . ,face)))
)
)
`(modify-face ',face ,color1 ,color2 nil t nil nil nil nil)
)
)
and something occured to me. When compiling I access several environmental variables giving information about the system, for example[2], the full name of most programs called by some mode that uses comint[3]. Rather then reading environmental variables, i could use some autoconf like tool to tweak the .emacs files and then compile them.
The problem is that autoconf is just plain ugly. I considered cmake, but the documentation is very poor especially on constructing your own build system. I'm not familar with alternate systems.
Suggestions?
[1]: To make clear, by .emacs setup I mean the 30 or so files and two subdirs of code that I have. Not to mention several packages that ( well at the time of inclusion ) are not part of the standard emacs distribution.
[2] I've replaced eg with "" since apparently many people do not know that eg means for example. Either that or they don't know what an example is.
[3] Such as diff-mode, and ruby-mode.

which diff?
More details would be useful here. Are these environment variables that you set yourself? or things provided by your distro?
Somewhat ironically, it sounds suspiciously like emacs' incredibly powerful built-in scripting is what you're looking for.

I agree with jkerian: why are you assembling your .emacs from parts? Here is what I do: break it down by language or feature and use require and provide. My .emacs looks like:
; -*- emacs-lisp -*-
(add-to-list 'load-path "~/elisp/personal")
(require 'jdk-generic)
(require 'jdk-haskell)
(require 'jdk-keywiz)
(require 'jdk-lua)
(require 'jdk-ocaml)
(require 'jdk-org)
(require 'jdk-php)
(require 'jdk-tex)
(require 'jdk-text)
(require 'jdk-whitespace)
Each individual file in ~/elisp/personal then sets up support for a language or whatever, then provides jdk-whatever. Here is jdk-lua.el:
(add-to-list 'load-path "~/elisp/packages/lua-mode-20071122")
(add-to-list 'auto-mode-alist '("\\.lua$" . lua-mode))
(autoload 'lua-mode "lua-mode" "Lua editing mode." t)
(provide 'jdk-lua)
Notice that I keep all elisp packages in ~/elisp/packages. This means I can copy my .emacs and ~/elisp directory just about anywhere and have it work straight away.

From what I understand, you want a script to autodetect where are your tools (like diff, grep...) instead of manually telling your .emacs where they are through environment variables.
If you are on a unix-like platform, all your tools like diff, grep, should already be on your PATH and emacs should have no problem finding them. So, in your .emacs you should not use any environment variable and put directly tools name in your configuration.
If your goal is to make a portable .emacs that could be executed on Windows for example, then you should put all the gnuwin32 tools in your PATH too, so that emacs find them without problem. But for Windows, you'll have to do many other tiny arrangements for emacs commands to work properly as on a unix system.
Using a tool like autoconf is something very time-consuming for something that could be well handled by customizing one single .emacs file. If you have specific things to do for a particular system, you could write elisp code like this :
(if (eq window-system 'w32)
(progn ... ))
Also, if you want to automate the byte compilation of all your .el files, you could use a command like this on your shell :
emacs --batch -f batch-byte-compile *.el

Related

how to alias external commands in emacs 27

I am trying to get Emacs 27 working for javascript + flow.
There are many steps/packages/configs to get this to work.
One particular step I am currently stuck on.
I cannot install npm packages globally (because our monorepo uses different versions of node_module packages for different apps within the repo).
So we cannot install flow, typescript and other things with npm -g
Instead, we need to point emacs to ./node_modules/.bin/flow (as an example).
Here is a concrete error message I am getting when starting emacs
Command "javascript-typescript-stdio" is not present on the path.
Command "typescript-language-server --stdio" is not present on the path.
Command "flow lsp" is not present on the path.
So, I would like, if possible to define in my .emacs
javacript-typescript-stdio
typescript-language-server
flow
such that they will point to /node_modules/.bin/
where is directory from which I start emacs
When searched for this topic, most queries came back with something about aliasing internal emacs functions, but that's not what I am looking for.
My .emacs section relevant to this:
;; lsp-javascript specific start
;; https://github.com/emacs-lsp/lsp-mode/issues/489
(use-package js2-mode
:mode "\\.js\\'"
:init
(add-hook 'js2-mode-hook #'js2-imenu-extras-mode)
(setf js2-mode-indent-inhibit-undo t)
:config
(with-eval-after-load "lsp-javascript-typescript"
(add-hook 'js2-mode-hook #'lsp)))
;; for flow start
(add-hook 'js2-mode-hook 'flow-minor-enable-automatically)
;; for flow end
;; JSON
(use-package json-mode
:defer t)
The exec-path holds locations to search for executables, so adding an entry there should work,
(add-to-list 'exec-path "./node_modules/.bin")
In this case, the path is relative to default-directory, which see.

(message "%S" load-path) and (describe-variable load-path) give different results

(message "%S" load-path) and (describe-variable 'load-path)
give different results.
Several more path like "/Users/updogliu/.emacs.d/elpa/flycheck-20140323.828" appeared in the latter.
How can I make (require 'flycheck) use the "describe" one load-path?
To setup Flycheck properly, you do not need to require Flycheck. Instead, just enable Global Flycheck Mode:
(add-hook 'after-init-hook #'global-flycheck-mode)
This will enable Flycheck for all supported languages.
To make (require 'flycheck) work in your init.el, you need to add (package-initialize) at the very beginning of your init.el.
(package-initialize) sets up Emacs' built-in package system, which includes adding all packages to the load-path. Emacs calls this automatically, but only after your init.el has been processed, hence the use of after-init-hook to enable Flycheck.
If you added a message call to your init.el without calling (package-initialize) first, you'll hence see the standard load-path without any of your packages.
To make your packages available in your init.el right away, you need to call (package-initialize) manually, at the beginning of your init.el.

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!

Loading packages installed through 'package.el' in Emacs24 [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Emacs 24 Package System Initialization Problems
I am using Emacs 24. I have the ELPA and Marmalade repos added. Using 'package' I installed 'auto-complete'. I have the following lines added to my init.el:
(require 'auto-complete-config)
(ac-config-default)
When I start Emacs, I get the error
File error: Cannot open load file, auto-complete-config
But then I use
M-x load-file
and load the same ~/.emacs.d/init.el file, it then works fine with the prompt saying
Loading /home/user/.emacs.d/init.el (source)...done
How is the usual loading different from the 'M-x load-file' command? In the start of the init.el file I do the following, is this somehow effecting the package from loading.
(add-to-list 'load-path "~/.emacs.d")
(load "custom_code")
As mentioned in the comment below: The answer by phils to the duplicate question is probably more helpful than this one
This almost certainly means that your init.el file is getting run before the code that sorts out the packages for package.el. The latter code adds the directory with the auto-complete library to your load path.
I'm still using ELPA, rather than package.el. With elpa, there's a snippet that looks like this that gets installed at the bottom of your .emacs.
;;; This was installed by package-install.el.
;;; This provides support for the package system and
;;; interfacing with ELPA, the package archive.
;;; Move this code earlier if you want to reference
;;; packages in your .emacs.
(when
(load
(expand-file-name "~/.emacs.d/elpa/package.el"))
(package-initialize))
As the comment suggests, you probably want to put your equivalent package.el initialization code before the stuff that loads init.el.
Finally: I notice you mention adding .emacs.d to your load-path. The Emacs load path is not recursive, so that probably won't do what you need (assuming that your libraries live in subdirectories). Years ago, I wrote this snippet to load up various libraries of elisp code that I'd written. You might find it useful. (Obviously, it'll only work on unixy systems with a shell and a find command. It's reasonably slow, but this seems to be shell-command-to-string, which takes several milliseconds even running "echo hello" or the like)
(defun find-elisp-dirs (dir)
"Find all directories below DIR containing elisp sources, ignoring those"
(split-string
(shell-command-to-string
(format "find %s -iname '*.el' -printf '%%h\\n' | sort -u"
(expand-file-name dir t)))))

How to install the slime into emacs under Windows7

How to install the slime into emacs under Win7?
I download a compact package with '.tgz'. But it seems for linux. But there is really not one thing for windows(win 32 OS).
I unfold this package and I find there are lots of documents.
It's actually the same as for other operating systems, as far as I can tell. (At least, it always worked for me under FreeBSD/ArchLinux/Win7.) First, you unpack to a location you like, then add something like this to your .emacs (assuming you unpacked somewhere under your user directory):
(add-to-list 'load-path "~/my/path/to/slime/")
;; (add-to-list 'load-path "~/my/path/to/slime/contrib/") ; for optional features
(slime-setup
;; '(slime-fancy slime-asdf slime-references ; optional features
;; slime-indentation slime-xref-browser)
)
(setq slime-lisp-implementations
'((ccl ("~/path/to/ccl/wx86cl"))
(clisp ("~/path/to/clisp-2.49/clisp" "-modern"))) ; giving a command arg
slime-default-lisp 'ccl)
Restart Emacs or type C-x C-e behind each of these toplevel forms. Then, type M-x slime RET (or C-u M-x slime RET if you want to choose between the implementations in slime-lisp-implementations, otherwise slime-lisp-default will be used) and it should just work (it does for me). The setting of slime-lisp-implementations is optional – you can also give the path to your lisp implementation executable by hand when starting Slime.
Assuming you want to use Slime with CL, since there is no Clojure tag. If you want to use it with Clojure, things are unfortunately a little different and both versions don't play very nicely together. The recommended way for use with Clojure, last time I checked, would be installation using the package system of Emacs 24 or, if you're using an older version, ELPA (which is essentially the same).
This worked for me,
Get a Slime copy from https://github.com/slime/slime, either by git clone or by downloading the zip. Unzip and save it in D:/myuser/slime-2.13, for example
Download and install CLISP
Add this to the .emacs file, usually located in C:/users/myuser/AppData/Roaming:
; This is the path where you've saved Slime in the first step
(add-to-list 'load-path "D:/myuser/slime-2.13/")
(require 'slime-autoloads)
; This is the path where CLISP was installed.
; Use Progra~1 for "Program Files" and Progra~2 for "Program Files (x86)"
(setq inferior-lisp-program "/C/Progra~2/clisp-2.49/clisp.exe")