Assuming Emacs knows how it was started, you can access the full path
of the executable file by doing:
(expand-file-name invocation-name invocation-directory)
In my system, for instance, this returns "/usr/local/bin/emacs" on
my regular session and returns "~/.evm/bin/emacs" on my evm test
session. If you want to get fancy, you can also wrap that in a
system-name is a built-in function in ‘C source code’.
Return the host name of the machine you are running on, as a string.
It's also a variable, but (a) that's now deprecated, and (b) the function pre-dates it, so don't use the variable. It is safe and best to use the function in all scenarios.
You're probably looking for the package exec-path-from-shell. Once it's installed, put this in your .emacs:
for emacs to read .bashrc on startup. That way you won't have to maintain paths in two places.
Although it is not clearly documented in its man page, emacsclient doesn't seem to accept a full command (i.e. program + arguments) as the alternate editor, only a program.
You could write a small shell script:
exec emacs -q -nw "$@"
and use it as the alternate editor:
export EDITOR='emacsclient -a PATH_TO_YOUR_SCRIPT'
Here's a quick custom function definition for your init file:
(defun which-linux-distribution ()
(when (eq system-type 'gnu/linux)
(shell-command-to-string "lsb_release -sd")))
then run it as:
or test for a known distribution, for example, as:
(when (eq which-linux-distribution '...
For your particular case, I think @InHarmsWay's answer is the best. But for the general case, you can use w32-version:
(pcase (and (eq system-type 'windows-nt)
(`(5 0 ,_) 'windows-2k)
(`(5 ,(or 1 2) ,_) 'windows-xp)
(`(6 0 ,_) 'windows-vista)
(`(6 1 ,_) 'windows-7)
(`(6 2 ,_) 'windows-8)
(`(6 3 ,_) 'windows-8.1))
Since this seems like a configuration based not on OS version so much as a particular machine's program installation, I think it would be better to conditionalize based on the system-name variable.
For the record, you can pass t as the 2nd argument to load, which will not signal an error if the listed file or library is not found.
There's no real standard method to detect the Linux distribution that a program is running under. Well, actually, there's a de jure standard: the lsb_release program. lsb_release -sir displays the name of the distribution and its version number. However, many Linux systems don't have the lsb_release program installed. Several distributions don't include it ...
The variable operating-system-release might be helpful. On my Arch Linux VPS, it is set to 3.14.1-1-ARCH. On Windows, it's nil.
So to check if I'm on Arch, I would do something like this:
(when (string-match-p "ARCH" operating-system-release)
This variable contains the same value output by the Linux command uname -r.
I found the answer to my own question; the relevant command is
More information can be found in the official documentation here.
(The solution provided by @legoscia above also works.)
emacsclient has a -a option which lets you specify an alternate editor to use if there is not an emacs process with a running server.
So emacsclient -a emacs may do what you want.
The alternate editor can also be specified to emacsclient via the ALTERNATE_EDITOR environment variable.
As for which of EDITOR or VISUAL to set: EDITOR was traditionally used ...
I just happened to notice this while looking for a an already implemented wsl-browse-url (thanks!), so will offer one other option:
(when (string-match "-[Mm]icrosoft" operating-system-release)
;; WSL: WSL1 has "-Microsoft", WSL2 has "-microsoft-standard"
It looks like that works on both my Debian WLinux WSL 2 environments.
You could also do (string-match-p "Microsoft" (shell-command-to-string "uname -a"))
Likely in your my-browse-url-function you're probably depending on a Windows
specific path to exist. You could just check that it exists and is executable
with file-executable-p like the following code does. However, this may not be
enough if you dual boot and mount the ...
I would check for an environment variable using getenv. You may want to check what variables are available in your typical WSL shell, but one option would be to check for a Windows-specific PATH entry, perhaps:
(string-match-p "Windows" (getenv "PATH"))
This is documented in chapter 49.4 The Emacs Initialization File of the Emacs manual (which is also included as part of Emacs, use C-h i to open the info browser which will show you this and many other manuals already on your computer). In short, Emacs loads both site-lisp.el and defaults.el in addition to your own startup file, and these two files may be ...
It's a wonder it should work in the first example. The ' (is a macro that) translates into (quote ...), so it inserts everything verbatim, without evaluating it. (i.e. without executing the cons forms.)
If you want to evaluate part of a quoted template, you can use quasiquote (aka backquote) using the ``` character, and "unquoting" the respective parts with ...