Emacs and Pandoc: can't create a pdf - emacs

I use GNU Emacs in a Mac. After installing the last version of Pandoc I can't create pdf files. Pandoc works well when I use the Terminal. I think that the problem has to do with the fact that Emacs doesn't find the template default.latex. This template is in my ~/.pandoc/templates.
This is the error message I receive when trying to create a pdf:
pandoc: /usr/local/share/pandoc-1.10.1/data/templates/default.latex: openBinaryFile: does not exist (No such file or directory)
I don't understand why Emacs is trying to find default.latex here.

(setq pandoc-binary "/usr/local/bin/pandoc")
This answer assumes you do not have a folder named pandoc inside of /usr/local/bin/ and that the actual executable has an absolute path of /usr/local/bin/pandoc. If the executable is buried deeper in another folder or more, then adjust the path in this example accordingly. The code at the top of this answer goes in your .emacs file.
You may also wish to modify this variable depending upon your preferred setup:
(setq pandoc-data-dir "~/.emacs.d/pandoc-mode/")

You could achieve a more general solution using exec-path-from-shell:
A GNU Emacs library to ensure environment variables inside Emacs look the same as in the user's shell.
Just install it, require it (only if your aren't using MELPA) in your .emacs file and add this line to it:
(exec-path-from-shell-initialize)
For more information see the usage section in the README.

Related

How to set executable path for a package on a configuration file on Emacs?

I want to use "ediprolog" package on Emacs. I followed installation and usage instruction here https://www.metalevel.at/ediprolog/ and he says:
The two most important configuration options are:
ediprolog-system, either scryer (default) or swi
ediprolog-program, the path of the Prolog executable.
So I tried C-X , customize-group , ediprolog and checked the configuration file. The files looks like this:
To be honest I have no idea how, where can I edit to add the prolog executable path ~/.cargo/bin/scryer-prolog. In addition, Emacs says You can't edit this part of the Custom buffer when I tried to type something on the file.
And as I can expected, when I run ediprolog-dwim, "view-echo" says ediprolog-run-prolog: No prompt from: scryer-prolog, probably because I don't set the path on a configuration file.
I'm noob to Emacs and the package also, sorry about that, but I'm really struggling to achieve this step. Your comments must be really helpful for me. Thanks.
Try adding the path to the exec-path variable in emacs: when emacs forks off a subshell, this variable is added to the PATH that is passed to the subshell:
(add-to-list 'exec-path (expand-file-name (substitute-in-file-name "$HOME/.cargo/bin")))

My .emacs.el file is not loading, how can I get it to load? [duplicate]

I tried looking for the .emacs file for my Windows installation for Emacs, but I could not find it. Does it have the same filename under Windows as in Unix?
Do I have to create it myself? If so, under what specific directory does it go?
Copy and pasted from the Emacs FAQ, http://www.gnu.org/software/emacs/windows/:
Where do I put my init file?
On Windows, the .emacs file may be called _emacs for backward compatibility with DOS and FAT filesystems where filenames could not start with a dot. Some users prefer to continue using such a name, because Windows Explorer cannot create a file with a name starting with a dot, even though the filesystem and most other programs can handle it. In Emacs 22 and later, the init file may also be called .emacs.d/init.el. Many of the other files that are created by Lisp packages are now stored in the .emacs.d directory too, so this keeps all your Emacs related files in one place.
All the files mentioned above should go in your HOME directory. The HOME directory is determined by following the steps below:
If the environment variable HOME is set, use the directory it indicates.
If the registry entry HKCU\SOFTWARE\GNU\Emacs\HOME is set, use the directory it indicates.
If the registry entry HKLM\SOFTWARE\GNU\Emacs\HOME is set, use the directory it indicates. Not recommended, as it results in users sharing the same HOME directory.
If C:\.emacs exists, then use C:/. This is for backward compatibility, as previous versions defaulted to C:/ if HOME was not set.
Use the user's AppData directory, usually a directory called Application Data under the user's profile directory, the location of which varies according to Windows version and whether the computer is part of a domain.
Within Emacs, ~ at the beginning of a file name is expanded to your HOME directory, so you can always find your .emacs file with C-x C-f ~/.emacs.
There's further information at HOME and Startup Directories on MS-Windows.
It should be stored in the variable user-init-file. Use C-H v user-init-file RET to check. You can also open it directly by using M-x eval-expression RET (find-file user-init-file) RET
Open the file like this in Emacs for Windows:
C-x C-f ~/.emacs
More information in the Emacs Wiki
On my Vista box it's in C:\Users\<USER>\AppData\Roaming\
Note that it may NOT be enough to just type Ctrl-x Ctrl-f ~/.emacs and create the file.
It may be that your Emacs application uses a different place to store your init file, and if so, then creating the file ~/.emacs simply creates a useless file which your Emacs application ignores.
Also, you may want to do more than just access the .emacs init file, but you may want to know where it is, i.e., its pathname.
To get at this there are two methods:
Easy way: type Ctrl + H V user-init-file Return
Slightly trickier way:
You can find out where your system is storing its own .emacs file by:
Click options and scroll down to "Set Default Font..."
Change the font setting and click okay
On the options menu, go down to "Save Options"
When the options are saved, the system saves its .emacs file,
and you can read the file path in the minibuffer at the bottom of the Emacs screen
In Windows 7 put your init.el file in C:\Users\user-name\AppData\Roaming\.emacs.d\, where user-name is your user/login folder.
Take care so your init.el file won't be named init.el.txt. This is something Windows does if you create your file with some editor like Notepad.
On versions of Emacs on Windows above 22, it seems to have moved to
~/.emacs.d/init.el
, ~ being the value of your environment variable HOME (see Control Panel → System → Advanced → Environment variables).
The file itself might not exist. In that case just create it.
You must create an emacs initialization file. One is not automatically created.
I had a similar issue and this answer tracks down what I did.
My issue was my ~/.emacs.el file was not loading. Strange because this has always worked for me.
This question/answer helped me but I had to put my init file in the %USERPROFILE%\AppData\Roaming\.emacs.d\init.el because this is apparently the default behavior on Windows.
To troubleshoot this, I ran the following in the emacs *scratch* buffer.
user-emacs-directory
"~/.emacs.d/"
When I saw user-emacs-directory was ~/.emacs.d, I simply moved my .emacs.el file to %USERPROFILE%\.emacs.d\init.el. But this still didn't work.
I continued with expand-file-name as shown below:
(expand-file-name user-emacs-directory)
"c:/Users/pats/AppData/Roaming/.emacs.d/"
Got to love how Windows works. (not) So I moved my emacs.el file to the %USERPROFILE%\AppData\Roaming\.emacs.d\init.el and this worked. The file was now being read. But I got other errors because my initialization file loaded other (personal emacs) files (in ~/myenv/emacs/*.el.
Warning (initialization): An error occurred while loading ‘c:/Users/pats/AppData/Roaming/.emacs.d/init.el’:
Hum... Seems like all my files ~/myenv/emacs/*.el would need to be moved in order for this to work but I didn't want to do that. Then I realized that because the HOME environment variable was not set, emacs was performing its default behavior.
SOLUTION
Once I set my windows HOME environment variable to %USERPROFILE% everything began to work like it has for the past 25 years. :-)
To set the HOME environment variable, I typed WindowsKey+"edit environment variables for your account" to open the Environment Variables dialog box, and entered HOME=%USERPROFILE%.
Now my emacs initialization file .emacs.el is is back to its rightful place $HOME/.emacs.el and not in %USERPROFILE%\AppData\Roaming\.emacs.d\init.el
To be fair, if Windows had just one place to put files for user installed packages the solution of making HOME=%USERPROFILE\AppData\Roaming might be acceptable, but because some applications use %USERPROFILE%, some use %USERPROFILE\AppData\Roaming and others use %USERPROFILE\AppData\Local it just makes it difficult to know where to find your configuration files.
I prefer having everything in my %USERPROFILE% or $HOME directory.
Another similar question was here:
Emacs init.el file doesn't load
As kanja answered, the path to this file is stored in the user-init-file variable (or if no init file exists, the variable contains the default value for where to create it).
So regardless of which of the possible init file names you are using, and which directory it is in, you should be able to visit your init file with:
M-: (find-file user-init-file) RET
Or display its full path in the echo area with:
M-: (expand-file-name user-init-file) RET
On Emacs 23 and Windows 7 it only works if you set:
HKCU\SOFTWARE\GNU\Emacs\HOME
After Emacs 27.1, emacs has started respecting the $XDG_CONFIG_HOME. The init file or the init directory can now be found in $XDG_CONFIG_HOME/emacs/init.el.
In Windows $XDG_CONFIG_HOME could translate to %LOCALAPPDATA%.
In any case you can use the following emacs variables to find out the location of the your initialization file by M-x eval-expression
user-init-file
or the emacs configuration directory
user-emacs-directory
I've found that Emacs 22 will occasionally open either "C:\Documents and Settings\username\Application Data\.emacs", or just "C:\Documents and Settings\username\.emacs" on my XP machine. I haven't found an explanation for why it occasionally changes it's mind.
~ will always point to whatever the current instance of emacs thinks is HOME, but kanja's tip (C-h v user-init-file) will always tell you what ~/.emacs actually maps to.
On Windows 8.1, if Emacs is started from Windows Explorer, a shortcut or from cmd console it uses C:\Users\<USER>\AppData\Roaming.emacs init file. When I start Emacs from PowerShell, Emacs looks for its init file in C:\Users\<USER> folder. The fix to this issue was to set the HOME user environment variable (Control Panel\System and Security\System->Advanced system settings->Advanced->Environment variables) to C:\Users\<USER>. After this change, no matter how I start Emacs, it uses the same init file (see the accepted answer of this question)
On Windows XP it's:
C:\Documents and Settings\yourusernamehere\Application Data\
There is a list of directories based on your Windows version and extra information:
http://www.gnu.org/software/emacs/manual/html_node/emacs/Windows-HOME.html
For WIndows7& Emacs26.3:
if HOME environment is set, then the .emacs file should be in that folder.
otherwise, it should be in c:\.
In both cases, if .emacs is not there, _emacs should be used.
This is because we cannot create .emacs file according to the windows file naming rules.(but we can download or copy it from somewhere else).

Change default save folder in LispBox

So I've finally decided to learn Lisp. I'm reading Practical Common Lisp and I'm using Lispbox (not the one the book recommends - it's no longer available, but it seems this is suitable nonetheless).
So far in my career I have managed to avoid wresting with emacs, but I guess that part of my life is over :-) Actually, I'm kind of excited - this is a brand new world.
When saving .lisp files, the out-of-the-box setup dumps these files into the lispbox-0.7 folder (which is also the LISPBOX_HOME env.var). My math teacher taught me, "If you don't know what you're doing, at least do it neatly." So I want to at least keep my work in a nice tidy folder. I can specify the full path on saving/loading. But can I tell (lispbox|emacs|whatever) to use a different folder by default?
If it matters: I will likely use the Windows version more often, but I also have a setup on Ubuntu.
I have looked at this and this and this. I tried adding these to the .emacs file (one at a time):
(setq default-directory "C:/Work/lisp/")
(cd "C:/Work/lisp/")
To open the .emacs file I used C-x C-f~/.emacs
If I try changing the LispBox shortcut's "Start in" property, it fails to load at all.
M-xcd c:/work/lisp does work, but I have to do it every time I launch LispBox
What I'm doing in the meantime: I've created a separate lisp folder beside the lispbox-0.7 folder. That way I can prepend ../lisp/ before any filename. This isn't so bad, especially with the tab auto-complete.
Found it!
The reason modifying .emacs wasn't working is because of the lispbox.bat file. It has this line:
%EMACS% --no-init-file --no-site-file --eval=%TO_EVAL%
So took out the two "no" parameters, leaving this...
%EMACS% --eval=%TO_EVAL%
...and it worked.
This worried me, though. Why would the default not want to load the .emacs file? I guess once I understand all of this better I'll have an answer. Until then, I restored the above, the changed this line...
set TO_EVAL="(progn (load \"lispbox\") (slime))"
...to this...
set TO_EVAL="(progn (load \"lispbox\") (slime) (cd \"C:/work/lisp/\"))"
Now I'm happy.
I know nothing about Lisp Box, and not all of what you describe is clear to me. But here goes.
It sounds like you are looking for a way to make c:/work/lisp the default directory when you start Emacs. For that, using an MS Windows shortcut, putting that folder in the Start in field does indeed accomplish that. But you speak of a LispBox shortcut's Start in. If by that you just mean an Emacs shortcut, then it should work.
But of course you need to use Windows syntax for the folder - not c:/work/lisp, but c:\work\lisp.
Is that what the problem was?
The Windows shortcut is a Windows thing. Emacs is different: it accepts / as a folder separator.
Tip: If that solves your problem, you might also want to start Emacs in Dired mode on that same folder, that is, if that folder is the one you will use a lot. To do that, add that folder at the end of the command line - again, using Windows syntax, but between double-quotes:
c:\your\path\to\runemacs.exe "c:\work\lisp"
Try starting lispbox.bat from the directory you want to save files to. For example, from the OS command prompt:
cd c:\work\lisp
path-to-bat-file\lispbox.bat
You can also cd to c:\work\lisp in listbox.bat before it executes Emacs. For Linux it looks like this in lispbox.sh:
#!/bin/bash
if [ "${0:0:2}" = "./" ]; then
export LISPBOX_HOME=`pwd`/../../..
else
export LISPBOX_HOME=`dirname $0`/../../..
fi
cd ~/work/lisp
export SBCL_HOME=${LISPBOX_HOME}/sbcl-1.0.42/lib/sbcl
exec ${LISPBOX_HOME}/Emacs.app/Contents/MacOS/Emacs --no-init-file --no-site-file --eval='(progn (load "lispbox") (slime))'

Unable to open the C source code of Emacs functions

When I search for a function description [find-function] and I click on the link to the "--.c"
file I cannot open it and I get Emacs C Source dir: ~/ in the Minibuf. I am stuck there and I don't know what to do.
"The Emacs distribution includes the full source code for the manuals, as well as the Emacs Reference Card in several languages." gnu.org/software/emacs
Get the .tar.gz file that corresponds to your Emacs version (check with M-x emacs-version if you're unsure) from http://ftp.gnu.org/pub/gnu/emacs/, and unpack it. Then you can enter the path to where you unpacked it as response to "Emacs C Source Dir". (I suspect you need to specify the src subdirectory of the Emacs distribution, but I haven't tried it myself.)
After you download the soruce code, there is also a variable can custom the location of the source code. eg:
(setq find-function-C-source-directory "~/Projects/emacs-25.1/src/")

emacs on Windows: .emacs is no valid file name

I've found out where to put my .emacs file, but it seems it can't begin with a ".".
I tried naming it "emacs" or "_emacs", but how can I find out if it is used?
You can always create the file using Emacs itself: C-x C-f ~/.emacs. The ~ represents your home directory, which you can set as environment variable HOME.
Have a look at this page and this one for start up instructions.
If you are creating a file in Explorer, it won't allow you to use a .name (gives this error).
A simple work-around, if you have bash (cygwin, git-bash, or any other variant) installed is to use that to rename the file. It may also work in powershell or command prompt, I've not tested those.
Files can start with '.', this doesn't cause any trouble alone, but explorer won't let you name them with it.
Windows Explorer disallows the creation of filenames starting with a dot. A simple workaround with builtin Windows tools is to create the file with a dummy name (eg. _emacs), then use cmd.exe to rename it:
cd path/to/file
ren _emacs .emacs
Recent versions of windows (e.g. Windows 7) seem to allow creation of a .emacs file using windows explorer. When creating/renaming the file simply enter .emacs. instead of .emacs.
To test if the .emacs that you are editing is the .emacs that is being loaded, you could put the following elisp command in it:
(minibuffer-message "it worked")
Now exit and restart emacs, while watching the minibuffer at the bottom of the screen to see if it appears (it will only appear for 2 seconds).
Windows allows the creation and use of that type of file, but Windows Explorer does not allow a file to be named to that using Windows Explorer. Use another tool (like the command line, or emacs) to create the file with that name.