How to use a symbolic link to use emacs in Mac OS - macos

I want to create a command line executable which will spawn an emacs window/application.
I searched on the internet and found that the emacs shipped with Mac is not supported in X11 window So, I downloaded the latest emacs from http://emacsformacosx.com/ and installed it in my mac.Then I go to the /usr/bin directory and create a symbolic link like this:
sudo ln /Applications/Emacs.app/Contents/MacOS/Emacs xemacs
when I run this symblolic link by ./xemacs it says(. means /usr/bin):
Warning: arch-dependent data dir
(/Users/david/src/emacs-dev/ftp-versions/emacs-24.2/nextstep/Emacs.app/Contents/MacOS//libexec/emacs/24.2/x86_64-apple-darwin/)
does not exist. Warning: arch-independent data dir
(/Users/david/src/emacs-dev/ftp-versions/emacs-24.2/nextstep/Emacs.app/Contents/Resources/share/emacs/24.2/etc/)
does not exist. Error: charsets directory not found:
/Users/david/src/emacs-dev/ftp-versions/emacs-24.2/nextstep/Emacs.app/Contents/Resources/share/emacs/24.2/etc/charsets
Emacs will not function correctly without the character map files.
Please check your installation!
But if I run the Emacs binary in directory /Applications/Emacs.app/Contents/MacOS/ it starts the application without any error.
Any one knows how to solve this problem?

Up to this point I think the best way is to create an executable script under /usr/bin which will execute the binary file /Applications/Emacs.app/Contents/MacOS/Emacs. The reason I didn't use "open" command is that I need to use some Emacs binary arguments. Compared to "open" this method can spawn multiple instance of emacs.
The script is :
#! /bin/sh
/Applications/Emacs.app/Contents/MacOS/Emacs "$#"
Then make it executable by doing chmod +x script.sh
then make the symlink
ln -s "/usr/local/bin/script.sh" /usr/local/bin/xemacs

You could use an alias: alias emacs="open -a Emacs --args <youroptions>.
The option --args allows you to pass options directly to emacs (e.g., -q avoids the evaluation of the init script).

Related

alias in .bashrc using Mac OSX: command works on the command line but in an alias it doesn't work

I realise there are a few questions similar to this but nothing that fully addresses the issue I'm getting.
I'm writing a few alias' for terminal commands I often use.
$ cd ~/Documents/blah/blah/blah
This works as a terminal command, but when I try to turn this into an alias:
alias pie='cd ~/Documents/blah/blah/blah'
This doesn't work, -bash: cd: Documents/blah/blah/blah: No such file or directory
I'm storing the alias in .bashrc in my home directory. I'm using Mac OSX.
Anyone know why it would work as a straight command but not an alias?
Similarly, I use a vagrant machine, and I'd like the chain together two commands: one to ssh to vagrant and the other to open the shell:
alias vshell='vagrant ssh && python manage.py shell
But this doesn't seem possible, it only ever executes the first command, maybe because this takes a little longer to complete?
Thanks

Executing MSYS2 Emacs from Windows command line or shortcut

I recently installed MSYS2 with Emacs (64-bit) and am currently calling that Emacs from a Windows shortcut. It works fine, exactly like if I had downloaded the Emacs executable for Windows and unzipped it somewhere. Which is to say, it picks up all of my Windows environment variables and such.
For various reasons, I would prefer to run Emacs from an MSYS2 bash shell and use the environment variables in that shell. As it stands, I can open an MSYS2 MINGW64 shell, type emacs on the command line, and everything works the way I want it to.
Now I would like to package the whole thing up into either a one-liner I can stuff into to a Windows shortcut or a script I can call from a Windows shortcut. With the help of this post, I came up with the following:
C:\msys64\bin\mintty.exe /bin/env MSYSTEM=MINGW64 /bin/bash -l -c /mingw64/bin/emacs
This successfully opens Emacs, but fails to load the .bashrc file that I source in .bash_profile in the usual manner:
if [ -f "${HOME}/.bashrc" ] ; then
source "${HOME}/.bashrc"
fi
I define a function in .bashrc that I call in .bash_profile, so this is kind of important. It did not take much effort to realize that the problem is that HOME is not defined, so .bashrc is simply not found. However, if I define HOME like so:
C:\msys64\bin\mintty.exe /bin/env HOME=/home/alanhr MSYSTEM=MINGW64 /bin/bash -l -c /mingw64/bin/emacs
I get exactly the same result: .bashrc is not found and my function is not executed. Here's where it gets weird. If I simply leave off the call to emacs like so:
C:\msys64\bin\mintty.exe /bin/env HOME=/home/alanhr MSYSTEM=MINGW64 /bin/bash -l
I get a bash shell where .bashrc has been loaded correctly and my function is correctly executed. I can type emacs on the command line and have it function exactly as I want it to.
This feels like a classic case of missing something that is right under my nose, but I have read the bash man page to no avail. Does anyone have any idea how I can make this work?
It is the -i option to load .bashrc. The following works for me:
C:\msys64\usr\bin\mintty.exe -w hide /bin/env MSYSTEM=MINGW64 /bin/bash -l -i -c /mingw64/bin/emacs

How to open emacs gui/ide from mac terminal?

I'm trying to open files up on emacs outside of the terminal. I prefer a gui/ide environment when I code instead of doing it through a terminal. I initially thought that typing emacs filename.py would open that file through Emacs.app, however it only allowed me to edit the file through the terminal. When this didn't work, I looked into editing the .profile and .emacs files in my home directory but this was to no avail.
Maybe this is more intuitive than what I've read but I can't seem to figure it out. Any help is appreciated.
Assuming you have Emacs installed from Homebrew like this:
brew install emacs --with-cocoa
Just type the following command to open Emacs.app from terminal:
open -a Emacs filename.py
If you want all files opened in the same frame, instead of new frames, put this into your .emacs file:
(setq ns-pop-up-frames nil)
The best way to open files in Emacs from the terminal is the emacsclient command, which will open the file in your existing Emacs app (preventing startup time). If you're on OSX and you installed Emacs through Homebrew, the emacsclient binary will already be set up. (In your Emacs config, you have to include (server-start) somewhere.)
If you actually want to spin up a new GUI app instance instead, you can set up your own shell script and put it in your PATH somewhere before the existing emacs binary. It sounds like you're using Homebrew, which sets up the emacs binary as the following shell script:
#!/bin/bash
/usr/local/Cellar/emacs/24.3/Emacs.app/Contents/MacOS/Emacs -nw "$#"
The -nw is what prevents Emacs from opening in GUI mode. You can make your own emacs shell script and leave out -nw:
#!/bin/bash
/usr/local/Cellar/emacs/24.3/Emacs.app/Contents/MacOS/Emacs "$#"
To do what you want, you'd need to find the location of the actual binary contained in Emacs.app, and use that as the command instead of emacs. Most likely, it's at
/path/to/Emacs.app/Contents/MacOS/Emacs
Which, if you have Emacs.app in your Applications folder, as would be typical, would be
/Applications/Emacs.app/Contents/MacOS/Emacs
To set it up with a shorter command to use, you could try adding to your .profile (I don't know what shell you use) the following line, or whatever equivalent it has for your shell (This works for bash and zsh, at least):
alias emacsgui='/Applications/Emacs.app/Contents/MacOS/Emacs'
The modern way to go about this is by installing Emacs using Homebrew Cask:
brew cask install emacs
Source: this comment by Homebrew project leader Mike McQuaid, which reads:
Cocoa support for Emacs will not be accepted. This is provided by brew cask install emacs.
One should link emacs to /Applications if not already done,
brew linkapps emacs
to link the emacs to symlink emacs installed in Cellar. Once symlinked, you can open emacs by
open -a emacs
as already pointed out by #katspaugh
brew doesn't have cask command anymore.
I used brew install emacs and I can find Emacs app installed in my application directory.
You can also head to https://emacsformacosx.com and download the .dmg file.

Mac os x: How to have makefile reference /Applications/application

OS Mac OS X 10.6.6
emacs 23.2.1
I'm currently trying to install magit on carbon emacs using their proposed make solution. I'm an almost complete makefile newby so I might be on the complete wrong path altogether.
Makefile displays:
%.elc: %.el
$(BATCH) --eval '(byte-compile-file "$<")'
which gets expanded to:
emacs -batch -q -no-site-file -eval "(setq load-path (cons (expand-file-name \".\") load-path))" --eval '(byte-compile-file "magit.el")'
What I do understand. However it comes back with:
Cannot open load file: subst-ksc
What after a bit of googling reveals some missing libraries. I also realized that the emacs referenced in the expanded command is pointing to /usr/bin/emacs which is one big file, I don't see the normal lisp / site-lisp / etc directories. I also know that my prefered emacs is carbon emacs located in /Application/Emacs.app which just opens when clicking on it, or alternatively, I can open it in with the terminal:
open /Application/MyApp.app
Finally the title question: How can I make Makefile using the Emacs.app on the applications directory? I hope someone here knows the answer, or can point me to alternatives.
regards,
Jeroen.
bash-3.2$ EMACSLOADPATH=/usr/share/emacs/22.1/site-lisp:/usr/share/emacs/22.1/lisp emacs - batch -eval '(print "hi")'
"hi"
bash-3.2$ emacs -batch -eval '(print "hi")'
Cannot open load file: subst-ksc
bash-3.2$
bash-3.2$ emacs -batch -eval '(print emacs-version)'
Cannot open load file: subst-ksc
bash-3.2$ unset EMACSLOADPATH
bash-3.2$ emacs -batch -eval '(print emacs-version)'
"22.1.1"
I had the same error Cannot open load file: subst-ksc on OS X Maverick running
cask exec emacs --no-site-file --no-site-lisp --batch \
\
-f batch-byte-compile projectile.el
I solved it with the method given here.
Replace the /usr/bin/emacs file by the following script:
#!/bin/sh
/Applications/Emacs.app/Contents/MacOS/Emacs "$#"
With that manner the emacs command will run your actual Emacs.

emacs on OS X 10.6

I am a new iMac user. I have extensive experience with Linux on a PC. I downloaded latest version of emacs to the Applications folder. I want to invoke emacs from the command line. However, the default path for emacs is /usr/bin/emacs. what is the best practice for adding the new emacs to the path? I am tempted to create a ~/bin directory and a link to the new emacs and adding ~/bin to the beginning of my path. This is how we did things in our software development environment on linux PC's
Best way is to use Homebrew and use
brew install emacs --cocoa
so you have a easy to update emacs installation. The Cocoa will make sure you have your mac keybinding working before emacs. Make the binary run at startup as a daemon (because it starts up not very fast), for instance:
/usr/local/Cellar/emacs/23.2/Emacs.app/Contents/MacOS/Emacs --daemon
And make an script to the emacsclient command and saved it to /bin/emacs file (don't forget to make it executable):
#!/bin/bash
exec /Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n -c "$#"
so when you fire up at bash "emacs something.txt" the already running emacs daemon opens it instantly. You can also extend it to open Emacs if the daemon is not running!
I tested it on the latest emacs 23.2, some features are not present on early versions.
Assuming you were still in linux land, wouldn't the canonical place to put this be in /usr/local/bin (and add that to your path?) ... I'd stick with that, if you were to go that route, but this is how I have my emacs setup:
I've downloaded the latest plain/vanilla Emacs from emacsforosx.com
I've made an emacs alias that I use to fire up a terminal-based version of emacs when I don't want (or can't) run the GUI version, like so:
alias emacs='/Applications/Emacs.app/Contents/MacOS/Emacs -nw'
If you want to fire up the GUI version of Emacs from the terminal, you can just type the following (which, AFAIK, is a mac-ism, so you wouldn't have known that coming from linux):
$ open -a Emacs
There's a slew of information about emacs on OS X at the emacs wiki.
~/bin or /usr/local/bin will work fine, as will manipulating your PATH.
Assuming you're using Emacs.app, simplest thing to do is to use open -a /Applications/Emacs.app "$#". open is the command line equivalent of double-clicking on something in Finder. Put that into a shell script, stick it into your PATH and go.
Installing emacs-app via MacPorts is probably the simplest way to get and maintain a Cocoa emacs.
You may wish to look into Aquamacs which is a further refinement of emacs for OS X. The emacs wiki page on Aquamacs is very helpful. It also has an option to add a little aquamacs script to your PATH that will open a file in the aquamacs GUI.
I create a shell script named emacs in my ~/bin directory containing:
open -a Emacs "$#"
Obviously, ~/bin needs to be before /usr/bin in my PATH which I set in ~/.profile so that it shadows the preinstalled emacs binary.
I also create a symlink via ln -s /Applications/Emacs.app/Contents/MacOS/bin/emacsclient ~/bin/emacsclient so that this also shadows the preinstalled emacsclient binary.
For additional connivence, I create an alias ec='emacsclient -a emacs -n ' and include (server-start) in my emacs init scripts. This enables me to open a file from the commandline using ec filename regardless if emacs is or is not already running.
Another tip: When you launch the emacs via Applications or open, emacs does not inherit the same path as you have in your terminal environment, so one thing I have found very useful is to run the following in my .profile after setting my path to change the PATH inherited cocoa applications:
defaults write ${HOME}/.MacOSX/environment PATH "$PATH"
That will work. If this is a native mac application, the binary is actually located under the application directory (not the capitalization of the binary): .../Emacs.app/Contents/MacOS/Emacs
Since you are coming from linux, you might be interested in MacPorts. This is a large collection of packages ported from linux. It allows packages to be installed and upgraded from the command line, doe sdependancy management, all the stuff you would expect. It includes a native version of Emacs, that can be invoked from the command line.

Resources