Run emacs command in terminal - emacs

I'm using Emacs Muse for work reasons and I don't really enjoy editing my .muse files in emacs.
I haven't found alternatives to publishing .muse files in another editor.
Is it possible to run Emacs commands from outside Emacs almost as if using it as a sort of interpreter?
I want to be able to go to the terminal and run something like:
> emacs -ne file_with_command file_to_publish.muse
The command in question is M-x muse-project-publish-this-file
edit: In Emacs, this command also has inputs that it prompts me to give one at a time. It's the style of publishing (html in my case) and the directory where the publication will go to.

muse-project-publish-this-file is not design to use in batch mode.Use muse-publish-file instead.
First,
git clone https://github.com/jwiegley/muse /path/to/muse
Then create script.el with content
(add-to-list 'load-path "/path/to/muse/lisp")
(require 'muse-publish)
(muse-publish-file "file_to_publish.muse" (muse-define-style "newstyle" nil) "/path/to/publish/directory")
notice is /muse/lisp not muse.
Last, emacs --batch -l script.el

Related

Emacs Slime - Comma doesn't work

I have emacs 24.5.1 on windows with slime installed. I am using sbcl for lisp. When I open up slime, it works, but whenever I try to use comma to invoke a command, it just enters a comma. I can't get to the slime command menu. Is there any other way to get to the command menu besides comma?
Found the solution.
When going to the slime git website, they said you should include this in your initialization file
(setq slime-contribs '(slime-fancy))
It works after adding that to init.el (equivalent of .emacs)

What to do if I cannot find my emacs init file?

I am trying to add haskell-mode to emacs by following these instructions:
http://doc.gnu-darwin.org/haskell-mode/installation-guide.html
This involves that I add some code to my ~/.emacs init file. However, my issue is that I cannot locate my emacs init file. I tried using find commands to locate it, as so:
find . -name "*emacs*"
find . -name "~/.emacs"
However none of these appear to be very successful, as I get either too many results, or no results.
So, given my situation, since I cannot locate my ~/.emacs init file, does this mean it does not exist? In that case, would it be smart to create one myself using the emacs editor? If so, are there any outstanding things I should know before attempting to create one?
C-x C-f ~/.emacs will take you to it.
See the Emacs manual, nodes Init File and Find Init.
To open your emacs init file, type M-: (find-file user-init-file) RET. If you only want to see its path, you can use C-h v user-init-file RET.
You can also create it yourself, if I'm not wrong installing emacs doesn't create automatically the file all the times. Just type in the terminal with your text editor (vim, vi, nano, etc) of preference:
vim ~/.emacs
And edit it the way you want :-)

Changing the initialization location of Emacs

I used to take the Programming languages course on Coursera and for the sake of the course i installed SML-Mode.
Now, I'd want to set up a Clojure environment in Emacs but instead of initializing Emacs from ~/.emacs.d, it initializes from the Users/karthik/Documents/sml-mode/sml-mode-startup
I deleted the sml-mode folder and on Emacs startup it shows me a warning about the files not being present. How I do point Emacs to load Emacs Live from the home folder.
I'm an Emacs newbie.
One easy way to do it, is
save you closure settings in /some/dir/my-closure-settings.el and call emacs as the following (to learn about -q -l , try emacs --help )
$ emacs -q -l /some/dir/my-closure-settings.el
or even placing an alias in bashrc,
$ alias closure-emacs='emacs -q -l /some/dir/my-closure-settings.el'
$ closure-emacs # will start emacs with your closure settings.
As you progress in learning some elisp, you will want to do it in one folder.
Assuming you installed Emacs yourself, and this SML-mode was an independent package, then I would speculated that it may have modified your site-start.el.
See if running emacs --no-site-file makes a difference.
If that's the issue, you can visit the file with:
M-: (find-library site-run-file) RET
You might also check:
C-hv user-emacs-directory RET
when running emacs in various ways:
emacs
emacs --no-site-file
emacs -q
emacs -Q
Unless it's a custom binary, at some point it should tell you "~/.emacs.d/"
Installing SML-mode does not change the place of the main initialization file, which is one of ~/.emacs or ~/.emacs.d/init.el. So look at those files (which ever of the two is present), and if none is present, then just create it and add what you need in it.
BTW, it looks like you're using an old sml-mode package (the newer one doesn't have an sml-mode-startup.el file). So please try and make sure the documentation that pointed you to that mode is updated: nowaday sml-mode should be installed from GNU ELPA, i.e. via M-x package-list or M-x package-install.

.emacs Edit to Always Start Emacs in Terminal Mode?

I use emacs as my editor-of-choice, and since I'm doing a lot of work in a terminal I always run emacs as
emacs -nw
so that it runs in the terminal instead of in a window.
I'd like to just run emacs and have it know that it should run in a terminal. My question is - how do I edit my .emacs file so that this is the default behavior?
You can't do this in the .emacs file. By the time that file is being parsed, the "chosen" emacs binary is already running.
You can install the emacs-nox package as one commenter suggests, or create an alias in your shell so that "emacs" is always treated as "emacs -nw".
Randy
I'm using a bash alias instead of .emacs to do that.
Add this line to your ~/.bashrc.
alias emacs='emacs -nw'
There is any easy way to solve the problem in general that has nothing to do with emacs at all and will work for any program that can choose between running in the console vs X:
unset DISPLAY
Of course you may not want to put that in your configuration file to be applied globally to all your shell sessions, so if you want it to apply to only emacs, then either call it from the command line like this:
DISPLAY= emacs
note the space!!! if you leave the space out it means you're setting the DISPLAY to emacs instead of setting DISPLAY to nothing... this command is a shorthand for:
DISPLAY=; emacs
So either use the above from the command line(s) or put that in a wrapper script that would look something like this:
#!/bin/bash
unset DISPLAY
exec emacs
I recommend the exec there because it will replace your wrapper script with emacs; to see the difference between the two you can run:
pstree -p
When I was first setting up a "emacs -nw" alias for emacs in windows I got stuck in a situation where I thought tototoshi's explanation hadn't worked. Yet all that was required was a restart of my terminal. Therefore, i think its worth mentioning that in windows (at least) if you are using emacs within the git bash terminal to create the .bashrc file and add "alias emacs='emacs -nw" to it (as tototoshi mentions) you have to close and reopen your terminal for it to work.

How do I byte-compile everything in my .emacs.d directory?

I have decided to check out Emacs, and I liked it very much. Now, I'm using the Emacs Starter Kit, which sort of provides better defaults and some nice customizations to default install of Emacs.
I have customized it a little, added some stuff like yasnippet, color-themes, unbound, and other stuff. I've set up a github repository where I keep all of the customizations so I can access them from multiple places or in case something goes bad and I lose my .emacs.d directory.
All of this is very nice, but there is a problem: Emacs takes about 1-2 seconds to load. AFAIK I can compile individual .el files with M-x byte-compile-file to .elc, and it works. But there are a lot of .el files, and I wonder if there is a way to compile them all with a simple command or something, to speed up the loading of Emacs. My Emacs is not always open, and I open and close it quite frequently, especially after I've set it up as a default editor for edit command in Total Commander to get used to it faster (yeah, windows xp here).
My Emacs version is 22.3. And yes, the default Emacs installation without any customizations fires up instantly.
I am not sure which version is preferred when loading, the .el or compiled .elc one by the way O.o
So, is there an elisp command or Emacs command line switch to make Emacs byte-compile everything in .emacs.d directory?
C-u 0 M-x byte-recompile-directory
will compile all the .el files in the directory and in all subdirectories below.
The C-u 0 part is to make it not ask about every .el file that does not have a .elc counterpart.
To automatically byte compile everything that needs byte compiling each time I start emacs, I put the following after my changes to load-path at the top of my .emacs file:
(byte-recompile-directory (expand-file-name "~/.emacs.d") 0)
Surprisingly, it doesn't add much to my startup time (unless something needs to be compiled).
To speed up my emacs, I first identified the slow parts using profile-dotemacs.el and then replaced them with autoloads.
You can use the --batch flag to recompile from the command line.
To recompile all, do
emacs --batch --eval '(byte-recompile-directory "~/.emacs.d")'
or to recompile a single file as from a Makefile,
emacs --batch --eval '(byte-compile-file "your-elisp-file.el")'
This is swaying a bit from the question, but to solve the problem of loading slowly you can use the new daemon feature in Emacs 23.
"If you have a lot of support packages,
emacs startup can be a bit slow.
However, emacs 23 brings emacs
--daemon, which enables you to start emacs in the background (for example
when you log in). You can instantly
pop up new emacs windows (frames) with
emacsclient. Of course, you could
already have an emacs 'server' in
older versions, but being able to
start it in the background makes this
a much nicer solution"
From http://emacs-fu.blogspot.com/2009/07/emacs-23-is-very-near.html
The command I use is M-x byte-force-recompile RET, it then asks the directory so, for example, I give it ~/.emacs.d/elpa/. It then recompiles everything in there, usually no need to delete .elc files first or mess with it in other ways.
For my using spacemacs, the command is spacemacs/recompile-elpa. The command byte-recompile-directory does not compile any file.