On OS X 10.5 Emacs 23.2, in dired-mode, if I try to sort by dired-sort-toggle-or-edit with prefix argument --sort=extension or -X, I get:
insert-directory: Listing directory failed but `access-file' worked
and the dired buffer becomes empty. I tried setting
(setq dired-use-ls-dired nil)
but this had no effect. dired-sort-toggle-or-edit and sorting by extension seems to work okay on my Ubuntu box. Anyone have a clue what's going on?
For now, I've also found another solution using ls-lisp
(when (eq system-type 'darwin)
(require 'ls-lisp)
(setq ls-lisp-use-insert-directory-program nil))
The ls that's installed on OS X doesn't support -X or any long arguments like --sort. Setting dired-use-ls-dired won't have any effect; dired will always use ls, but if that variable is non-nil, it will pass --dired to ls.
If you want that type of sorting, you can probably use something like fink to install coreutils, which will provide an ls more like what you're used to in Ubuntu.
Here are the steps for Emacs running on Snow Leopard 10.6.8 using coreutils installed through macports:
NOTE: My macports installation is different than the generic (/opt/...) -- i.e., I use /macports as the root. Altering the root setup is not required, it is just a personal preference of mine. For vanilla macport installations or alternative setups, adjust the path accordingly.
sudo /macports/bin/port install coreutils
This goes inside the .emacs or init.el:
;; sort directories first
(setq insert-directory-program "/macports/bin/gls")
(setq dired-listing-switches "-aBhl --group-directories-first")
NOTE: Using a symlink for gls/ls is not recommended because it breaks functionality with macports install and most likely other stuff too.
Alternative installation for users who want more control:
Download: coreutils-8.21.tar.xz from: http://ftp.gnu.org/gnu/coreutils/
If you do not have a utility to unzip an *.xz file, you can use a utility such as TheUnarchiver3.9.1.
Here is a quick reference to make the coreutils -- I set the installation location to my own personal preference instead of the default:
./configure \
--prefix=/Users/HOME/.0.data/.0.emacs/elpa
make
sudo make install
Insert these into your .emacs or init.el file -- adjust the path accordingly:
;; sort directories first
(setq insert-directory-program "/Users/HOME/.0.data/.0.emacs/elpa/bin/ls")
(setq dired-listing-switches "-aBhl --group-directories-first")
Still happening in 2020! If, like me, you're using brew as your open source package manager, this is the right solution to copy paste in your .emacs file, or wherever you keep your startup customizations:
(when (equal system-type 'darwin)
(setq insert-directory-program "/usr/local/opt/coreutils/libexec/gnubin/ls"))
(I check for the OS because I deploy my Emacs configuration on multiple systems).
Oddly enough, this happened suddenly on a Mojave system on which I routinely use Emacs since forever, and on which I am sure dired was working in the past. I guess that an update broke something that made dired use the correct binary, without having to manually set it.
This is not much different than lawlist's nice answer, but has slightly different information and is tailored to those who use the Nix package manager:
(use-package dired
:custom
;; See http://stackoverflow.com/questions/4115465/emacs-dired-too-much-information
;; NOTE: Just some information worth keeping in mind. More readable dired file
;; size output - consider adding F (make file type obvious), or p (p adds a
;; trailing slash to dirs, but makes moving dirs fail), and G (colorize) too.
(dired-listing-switches "-alh --group-directories-first")
:config
;; [[https://stackoverflow.com/questions/4076360/error-in-dired-sorting-on-os-x][macos - error in dired sorting on OS X - Stack Overflow]]
;; To fix the
;; (error "Listing directory failed but 'access-file' worked")
;; error. Emacs needs to use gnu's ls, which I get through nixpkgs' coreutils.
;; In my config, currently, Emacs is not picking up the path to my nix install
;; ls (todo: fix).
;;
;; Note that, unlike the info at the link provided above,
;; --group-directories-first is not needed to fix this error. I just like to
;; see the directories first in a dired buffer.
(setq insert-directory-program (expand-file-name ".nix-profile/bin/ls"
(getenv "HOME"))))
Related
Questions with similar titles (linked) do not cover the specific errors I am encountering, hence the new ask.
Context:
I am trying to set up an environment for working with scheme in emacs so I can work through the SICP book. I understand it is possible to integrate the two nicely so they work well together. I understand there are many ways of doing this even with extra features (I've seen the names quack/racket ...) but those seem like the more advanced options. Since I am having trouble setting up this bare basics 'run-scheme' in emacs I have not looked into these options extensively.
Where I'm at / What I've tried:
I downloaded MIT:GNU scheme 9.2 for OS X (x86-64). This works as expected and I can run the interpreter either from the terminal with:
$ scheme
or by executing the file "/Applications/MIT:GNU Scheme.app/Contents/Resources/mit-scheme" (which opens the interpreter in a new terminal window).
At this point M-x run-scheme returns a message saying that no such file or directory exists.
I read these two questions for reference and then:
I created a symbolic link to the binary/exec file "/Applications/MIT:GNU Scheme.app/Contents/Resources/mit-scheme" (which works perfectly when executed from finder/the terminal), then placed this file in "/usr/bin" with name "scheme".
At this point M-x run-scheme returns:
/usr/local/Cellar/emacs/24.5/Emacs.app/Contents/MacOS/Emacs:/usr/bin/scheme: Exec format error
Process scheme exited abnormally with code 126
The symlink file looked very out of place in the bin folder so not knowing what else to try I removed the symlink and instead created an actual copy of the mit-scheme exec file and placed that in "/usr/bin".
M-x run-scheme now returns this:
/usr/bin/scheme: can't find a readable default for option --band.
searched for file all.com in these directories:
/Applications/mit-scheme.app/Contents/Resources
Inconsistency detected.
Process scheme exited abnormally with code 1
Searching for help with understanding these error messages lead me to threads about issues with setting up scheme on windows OS, which is confusing, and I feel I am now out of my depth -
hoping someone knows where I'm going wrong.
End
It seems strange because I know that the 'M-x run-scheme' command is trying to access the location "/usr/bin/scheme" and I have made sure that such a location exists, and that the scheme exec file at that location works properly - I don't understand what other requirements emacs has for this to work.
What is the run-scheme command actually doing? What other requirements does it have to function as expected?
MIT Scheme looks for its libraries (including its 'bands') in a location derived from the executable's path. If the libraries are in a non-standard location, then the mit-scheme executable won't find them.
For example, in my setup, MIT scheme is located at: /usr/local/scheme/bin/mit-scheme and the band, and other stuff, is located at /usr/local/scheme/lib/mit-scheme/.
For Emacs I've defined:
(defun mit-scheme ()
(interactive)
(run-scheme "/usr/local/scheme/bin/mit-scheme -library /usr/local/scheme/lib/mit-scheme"))
Which ensures mit-scheme can find its library when, in Emacs, I perform M-x mit-scheme. If I want MIT Scheme to be the default, I would use:
(setq scheme-program-name "/usr/local/scheme/bin/mit-scheme -library /usr/local/scheme/lib/mit-scheme")
You'll need to set your values according to your installation. You also might have an option of setting MIT Scheme related environment variables to point to your library location. The relevent one is MITSCHEME_LIBRARY_PATH.
$ mit-scheme --help
Usage: mit-scheme --OPTION ARG ... --OPTION ARG ...
This machine accepts the following command-line options. The options
may appear in any order, but they must all appear before any options
for the band.
--library PATH
Sets the library search path to PATH. This is a colon-separated
list of directories that is searched to find various library files,
such as bands. If this option is not given, the value of the
environment variable MITSCHEME_LIBRARY_PATH is used; if that isn't
defined, "/usr/local/lib/mit-scheme" is used.
--band FILENAME
Specifies the initial band to be loaded. Searches for FILENAME in
the working directory and the library directories, returning the
full pathname of the first readable file of that name. If this
option isn't given, the filename is the value of the environment
variable MITSCHEME_BAND, or if that isn't defined, "runtime.com"; in
these cases the library directories are searched, but not the
working directory.
...
I'm also trying to play with the materials from SICP. It took a couple of hours and attempts to get things working.
I realized my paths were wrong after following Don't Panic! on Mojave (macOS 10.14).
I installed mit-scheme 10.1.5 from source running the installation steps from here and in the readme. My paths were different, which caused the --band command to fail.
If you're having issues double check all your paths are what you expect.
I used make install with default paths to install to /usr/local/bin and /usr/local/lib
Mac comes with emacs 22.1.1, which is old, but it works with the extra scripts from the professor for customizing emacs.
NOTE: If you quit emacs 22.1.1, it doesn't warn you about stopping scheme, which will lead to a 100% CPU usage process that you can't stop without Activity Monitor. Newer versions of emacs will prompt you to quit the scheme process before exiting (there may be a setting for older versions as well).
I installed emacs 26.1 using Homebrew and was able to get everything running after fixing these issues:
There is an error on newer versions of emacs (24+?) with ad-advised-definition-p, fix it by commenting out the function in "multi-term.el" around line 334:
; (defcustom multi-term-dedicated-skip-other-window-p nil
; "Default, can have `other-window' select window in cyclic ordering of windows.
; In cases you don't want to select `multi-term' dedicated window, use `other-window'
; and make `multi-term' dedicated window as a viewable sidebar.
;
; So please turn on this option if you want to skip `multi-term' dedicated window with `other-window'.
;
; Default is nil."
; :type 'boolean
; :set (lambda (symbol value)
; (set symbol value)
; (when (ad-advised-definition-p 'other-window)
; (multi-term-dedicated-handle-other-window-advice value)))
; :group 'multi-term)
Path setup
I had a warning:
Warning (initialization): Your ‘load-path’ seems to contain
your ‘.emacs.d’ directory: ~/.emacs.d
This is likely to cause problems...
Consider using a subdirectory instead, e.g.: /Users/paulsolt/.emacs.d/lisp
Which I solved by pointing the top line of the ~/.emacs file to:
;; (setq load-path (append (list "~/.emacs.d") load-path))
(setq load-path (append (list "/Users/paulsolt/.emacs.d/config") load-path))
The config folder already had all the scripts, that I think I was having issues getting Emacs to see.
I installed scheme from source without modifying install paths, so I changed this line:
;; This is the place where you have installed scheme. Be sure to set
;; this to an appropriate value!!!
;;(setq scheme-root "/mit/6.945")
(setq scheme-root "/usr/local")
Next to fix the issue that was causing --band to fail I modified this line.
(setq scheme-program-name
(concat
scheme-root "/bin/mit-scheme "
"--library " scheme-root "/lib/mit-scheme-c "
;;"--band " scheme-root "/lib/mit-scheme-c/all.com "
"--band " scheme-root "/lib/mit-scheme-x86-64/all.com "
"-heap 10000"))
My scheme library was installed in a mit-scheme-x86-64 folder.
Lastly, it appears that there's some other commands I had to comment out, since they don't seem to exist ...
;;(tool-bar-mode -1)
;;(scroll-bar-mode -1)
After all that setup I'm now able to create a scheme script in emacs, and I can run the script using the meta key (iTerm set my Alt key to Esc+):
M-x run-scheme
Tip: Being newer to emacs, I'm working through the emacs tutorial (C-h t) which is essential if you're going the text-based approach. In college I used emacs outside of terminal, but I'm giving it go inside the terminal this time to learn more hotkeys.
I am running emacs 24.3 on mac os x 10.9. I have installed the tuareg-mode for ocaml programming but am unable to compile using the command C-c C-b. On pressing the same, the minibuffer asks me about 'Caml toplevel to run: ocaml'. When I press enter it shows the error "Searching for program: No such file or directory, ocaml". What am I missing?
you need to setup PATH environment variable & the Emacs's exec-path variable to correct values. One possibility is to use something like (in your ~/.emacs):
(defun set-exec-path-from-shell-PATH ()
(let ((path-from-shell (shell-command-to-string "$SHELL -c 'echo $PATH'")))
(setenv "PATH" path-from-shell)
(setq exec-path (split-string path-from-shell path-separator))))
(when window-system (set-exec-path-from-shell-PATH))
to get the PATH from shell and both variables correctly. One advantage of this is that you will setup PATH only in one place - in your shell init script.
So I found this cool mode that autoloads the shell variables into emacs environment for mac users. Very handy:
https://github.com/purcell/exec-path-from-shell
Just install it and update your .emacs file and you are set.
I am using gnu global in emacs, everything is ok, but command "gtags-find-tag" search is too slow that cannot bear. only this command is very slow, the others like "gtags-find-rtag" is normal I think.
I delete other config such as cedet, so that exclude these effect, but this issue is still exist.
Do I miss some config steps of global or emacs? or anyone in other platform(linux) has this issue?
===
my Emacs is emacs for Mac OSX version is 24.3, GNU global is 6.2.8, and my config file is
(add-to-list 'load-path (expand-file-name "~/.emacs.d"))
(setq load-path (cons "/Users/xxx/.emacs.d/gtags.el" load-path))
(autoload 'gtags-mode "gtags" "" t)
(add-hook 'c-mode-hook
(lambda ()
(gtags-mode t)
))
I don't use Global (I do keep meaning to try it), but looking at the code, gtags-find-tag and gtags-find-rtag are very similar functions.
I presume the difference must either be in the completing-read phase, or the find phase, both of which are calling Global.
In the completing-read, 'gtags' passes the option -c, while 'grtags' passes -cr
In the find phase, 'gtags' passes -x, while 'grtags' passes -xr.
I would firstly try to establish whether it is faster outside of Emacs than it is inside it. The above might be sufficient for you to test this, but you should be able to figure out the exact commands being used by using M-x debug-on-entry RET call-process RET (which you can subsequently cancel with M-x cancel-debug-on-entry), and then running the gtags functions and seeing which arguments appear in the stack trace for that function call.
If you can't make heads or tails of the stack trace, try copying and pasting it into your question.
Edit:
Based on the information from the comments, it's appears that it's the case-insensitivity argument which is, for some reason, slowing things down to an unreasonable degree.
You should be able to disable that behaviour here:
M-x customize-variable RET gtags-ignore-case RET
As explained in here, putting (setq default-directory "~/Desktop/mag" ) in .emacs is supposed to change the default directory.
When I do that with the emacs on my mac, it doesn't work. C-x C-f still shows ~/ not ~/Desktop/mag.
(cd "Users/smcho/Desktop/mag") also gives me this error - Error: No such directory found via CDPATH environment variable
What's wrong with them?
The directory that appears in the prompt for C-x C-f ('find-file') comes from the value of default-directory, which is a buffer-local variable. When you first start Emacs, the initial buffer displayed is the GNU Emacs buffer. That buffer's default-directory is set from the variable command-line-default-directory.
So, try this:
(setq command-line-default-directory "~/Desktop/mag")
The straight-forward answer to your question is:
(setq-default default-directory "~/Desktop/mag")
Reading the documentation for the variable (C-h v default-directory RET) you'll see:
Automatically becomes buffer-local
when set in any fashion. This
variable is safe as a file local
variable if its value satisfies the
predicate `stringp'.
That said, opening a file automatically sets the default-directory to the path of the file...
So, if you always want find-file to start at that directory, you can use this:
(global-set-key (kbd "C-x C-f") 'my-find-file)
(defun my-find-file ()
"force a starting path"
(interactive)
(let ((default-directory "~/scratch/"))
(call-interactively 'find-file)))
This question may be a duplicate of Preventing automatic change of default-directory. Though it's difficult to tell.
In addition to the notes above regarding default-directory, I had to also prevent the emacs splash screen from starting in order to make subsequent commands like dired actually show their buffer when invoked from .emacs on startup:
(setq inhibit-splash-screen t)
I'm trying to get a compile command (rake cucumber) to run with a specific ruby version on my Mac OS X system, I use rvm to do this currently in the terminal. My ~/.MacOSX/environment.plist has the correct path in it, but emacs insists on prepending to this path and therefore making it useless. I've also tried:
(when (equal system-type 'darwin)
(setenv "PATH" (concat "/Users/fearoffish/.rvm/bin:/Users/fearoffish/.rvm/rubies/ruby-1.8.7-p249/bin:/Users/fearoffish/.rvm/gems/ruby-1.8.7-p249/bin:/Users/fearoffish/.rvm/gems/ruby-1.8.7-p249%global/bin:/Users/fearoffish/.rvm/bin"))
(push "/Users/fearoffish/.rvm/bin" exec-path)
(push "/Users/fearoffish/.rvm/rubies/ruby-1.8.7-p249/bin" exec-path)
(push "/Users/fearoffish/.rvm/gems/ruby-1.8.7-p249/bin" exec-path)
(push "/Users/fearoffish/.rvm/gems/ruby-1.8.7-p249%global/bin" exec-path)
(push "/Users/fearoffish/.rvm/bin" exec-path))
It was the desperate attempt of an emacs beginner to get what I wanted. It still prepends in front of it, so my path ends up being:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/fearoffish/.rvm/bin:/Users/fearoffish/.rvm/rubies/ruby-1.8.7-p249/bin:/Users/fearoffish/.rvm/gems/ruby-1.8.7-p249/bin:/Users/fearoffish/.rvm/gems/ruby-1.8.7-p249%global/bin
I don't want /usr/bin and others prepending, I want my path first and the emacs prepended path to be at the end, I reckon this would fix my problem.
I test this by simply opening Aquamacs and running meta-x compile and then echo $PATH.
Any ideas?
A small modification to the solution by sanityinc (couldn't find a way to enter it in the comments above -- is that just me?)
I use -l option to the shell to force a login shell (which reads .profile or .bash_profile), rather than an interactive shell (which only reads .bashrc).
I do some string trimming on the returned path (as inspection shows a newline sneaking in).
Modified code:
(defun set-exec-path-from-shell-PATH ()
(let ((path-from-shell
(replace-regexp-in-string "[[:space:]\n]*$" ""
(shell-command-to-string "$SHELL -l -c 'echo $PATH'"))))
(setenv "PATH" path-from-shell)
(setq exec-path (split-string path-from-shell path-separator))))
(when (equal system-type 'darwin) (set-exec-path-from-shell-PATH))
Everyone seems to have misunderstood the original issue: the path is already setup correctly in Emacs, and the correct path is already passed to the shell started by the compile command! So what gives? Here is the answer:
In MacOS X, there is a small tool called path_helper(1). It is called by default from /etc/profile, which is executed by Bash on shell startup. When you start a compilation from Emacs, it launches a shell (which by default is Bash on MacOS X), and therefore executes this path_helper tool. And here comes the key point: path_helper rearranges your path, moving the standard directories like /usr/bin in front of your custom added directories, no matter where you originally added them. Try this yourself by opening a shell and first having a look at what PATH is, and then execute /usr/lib/path_helper and have look at the resulting PATH!
The brute force solution for you might be to simply comment out the call to path_helper in /etc/profile. Note however that then you won't automatically get the paths in /etc/paths.d setup by path_helper, which is the tool's main purpose.
I don't have a Mac, so I cannot test this directly, but this can all be found in the *info* page Interactive Inferior Shell.
When you start a shell in Emacs, the process that gets spawned is the program in the Emacs variable explicit-shell-file-name (and if that is nil, the environment variables ESHELL and SHELL are used).
It then sends the contents of ~/.emacs_*shellname* (e.g. if your shell is csh, then ~/.emacs_csh would be sent over. Also, the appropriate .rc files for csh program is sourced, so you can update that as well (in my case .cshrc). Additionally, you can wrap customizations in the .rc file with a check for the environment variable INSIDE_EMACS (which which Emacs sets before it runs a shell).
You need to update those files to change the path in the shell, not the Emacs variable exec-path. exec-path - which is just a list of directories Emacs uses to find executable programs. The behavior of the executables are not affected by changes to exec-path.
I find the environment.plist scheme on Macs pretty ugly, so I use the following snippet, which assumes you want Emacs to use the same PATH that you see in your Terminal.app:
(defun set-exec-path-from-shell-PATH ()
(let ((path-from-shell (shell-command-to-string "$SHELL -i -c 'echo $PATH'")))
(setenv "PATH" path-from-shell)
(setq exec-path (split-string path-from-shell path-separator))))
(This works for me in Emacs 23; haven't tried it in other versions, but I'd expect it to work.)
try this maybe. replace path string with yours.
(add-to-list 'load-path "~/opt/swank-clojure/src/emacs")
As far as I observed, Emacs takes the path variable from the shell it is launched from, so one solution is to change $PATH in the shell before you launch Emacs.
One other approach I used, which is more flexible, is to use a Makefile and append a "source ~/script_that_set_path" in front of each make commands you have.
I have tried so many different approaches to this that ended up not using emacs to setup my compilation command environment.
What I do now is to create a run_helper.sh file that simply initializes a clean environment and then uses exec $* to execute the command passed as argument to run_helper.sh
This run_helper.sh is usually project specific, but I keep a template which I use to start with when I create a new project.
Then I simple run compile from emacs like bash run_helper.sh rspec path/to/tests for example.
If I am using this to run ruby tests, my helper initializes RVM to use the proper ruby and gemset. If I am using some other language it may just export required environment variables or perform some other initialization, but this way I can do it in bash script instead of always having to mess with emacs paths and elisp every time I start a new project.
Here's an example of a run_helper.sh file
#!/bin/bash
cd /Users/simao/Documents/sp
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"
source "$HOME/.rvm/scripts/rvm" # This loads the proper ruby and gemset from .rvmrc
export RAILS_ENV=test
exec $*
This also makes my tests run faster because I have lots of stuff in my .zshrc that I don't want to load just to run some tests.
It worked for me with two things.
First I followed sanityinc advice
An improved and modified version of the code snippet is now published as elisp library called exec-path-from-shell; installable packages are available in Marmalade and Melpa
I still had a problem with compile commands. Valko Sipuli is right there was a problem involving path_helper.
I commented the corresponding line in /etc/profile and it did not help. Problem still there.
I don't use bash but zsh. Digging a little I found /etc/zshenv. This file also calls path_helper.
After commenting the path_helper section in /etc/zshenv my path is finally correct