I am trying to get inf-ruby to work in Emacs. For the most part it works fine, except for the very annoying habit of echoing every input entered. Does anyone know what could be wrong?
I am using Carbon Emacs on OSX 10.5 with the default Ruby 1.8.6. My irb version is 0.9.5
The odd bit is that inf-ruby worked perfectly one time I opened it, but I can't figure out what I did differently that single time.
Add this to your init.el
;;
(defun echo-false-comint ()
(setq comint-process-echoes t))
(add-hook ’comint-mode-hook ’echo-false-comint)
;;
A little more explanation is on my blog post.
Related
I work a lot in a shell inside emacs (on a Mac). It used to be that, when I typed control-Q control-C, that would kill a process running in the shell. About a year ago, though, that stopped working for some reason; now it has no effect. Anyone know why, or another way of doing this?
I had the same problem using term-mode.
I bound term-interrupt-subjob to my keybinding of choice with:
(add-hook 'term-mode-hook (lambda ()
(define-key term-raw-map (kbd "C-'") 'term-interrupt-subjob)
I am not sure which mode you are using to interact with a shell from Emacs (the inferior shell, Emacs shell, or the terminal emulator). So you might have to modify this a little by replacing term-interrupt-subjob by, for instance, comint-interrupt-subjob and changing the mode hook.
To answer your questions in the comments:
You add the function in your .emacs file. For it to take effect, you need to evaluate it: you can select it and run M-x eval-region or you can restart Emacs.
If you are running M-x shell, you are using shell-mode.
Note that to know which major mode you are using, you can run describe-mode.
Since you are using shell-mode, you want to use add-hook 'shell-mode-hook instead of add-hook 'term-mode-hook and shell-mode-map instead of term-raw-map.
However, in shell-mode, C-c C-c does by default run the command comint-interrupt-subjob. So this should work out of the box as Rorschach said. I am not sure why it isn't working for you.
You can try:
(add-hook 'shell-mode-hook (lambda ()
(define-key shell-mode-map (kbd "C-c C-c") 'comint-interrupt-subjob)
to see if that helps. But this should already be set since it is the default, so it is really unclear whether it will solve your problem.
When I'm typing in the REPL of guile or mzscheme
(define x 15)
and then press arrow key I get
(define x 15)^[[D
Is it a terminal problem? or something needs to be configured? It's painful to rewrite a line for a simple edit
I found the answer for Guile, adding this in ~/.guile will cut it:
(use-modules (ice-9 readline))
(activate-readline)
I do not know what guile is, but for mzscheme, you can input
(require readline)
To interactively enable the arrow-key behavior you're looking for. To enable this behavior when the REPL starts, run it using
mzscheme -il readline
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"))))
I have configured my emacs to run zsh shell within ansi-term. However, copy/paste no longer works i.e. nothing is getting pasted from kill-ring to the terminal.
Changing the TERM to vt100, or eterm doesn't solve the problem.
Would appreciate any ideas or solution.
To provide context I have configured ansi-term as follows:
(global-set-key "\C-x\C-a" '(lambda ()(interactive)(ansi-term "/bin/zsh")))
(global-set-key "\C-x\ a" '(lambda ()(interactive)(ansi-term "/bin/zsh")))
You may want to simply switch between character mode and line mode while using the terminal. C-c C-j will run term-line-mode, which treats the terminal buffer more like a normal text-buffer in which you can move the cursor and yank text. You can switch back to character mode by running term-char-mode with C-c C-k.
As described in this lovely blog snippet, there's a function, term-paste, in term.el, that does exactly what you want. By default it's bound only to S-insert but the blog's recommended C-c C-y seems like a good suggestion.
ansi-term, in char-mode, takes the ordinary bindings for the terminal emulation. You need a new binding, plus a way to output to ansi-term correctly. I use this:
(defun ash-term-hooks ()
;; dabbrev-expand in term
(define-key term-raw-escape-map "/"
(lambda ()
(interactive)
(let ((beg (point)))
(dabbrev-expand nil)
(kill-region beg (point)))
(term-send-raw-string (substring-no-properties (current-kill 0)))))
;; yank in term (bound to C-c C-y)
(define-key term-raw-escape-map "\C-y"
(lambda ()
(interactive)
(term-send-raw-string (current-kill 0)))))
(add-hook 'term-mode-hook 'ash-term-hooks)
When you do this, C-c C-y will yank. It only does one yank, though, and you can't cycle through your kill-buffer. It's possible to do this, but I haven't implemented it yet.
The above solutions work well for copying text from some buffer to ansi-term, but they aren't able to copy text from ansi-term to another buffer (eg copy a command you just ran to a shell script you're editing). Adding this to my .emacs file solved that problem for me (in Emacs 24.4):
(defun my-term-mode-hook ()
(define-key term-raw-map (kbd "C-y") 'term-paste)
(define-key term-raw-map (kbd "C-k")
(lambda ()
(interactive)
(term-send-raw-string "\C-k")
(kill-line))))
(add-hook 'term-mode-hook 'my-term-mode-hook)
Note that if you want to bind kill/yank to a keystroke that starts with the ansi-term escape characters (by default C-c and C-x), and want this to work in the unlikely event that those change, you can instead define your keystrokes (without the leading escape) to term-raw-escape-map, as is done in user347585's answer.
These other solutions don't work well for me, switching between character mode and line mode causes ansi-term to stop working properly randomly, and setting ansi-term's term-paste to C-c C-y (based on Glyph's link), didn't work the code snippet was for term, not ansi-term:
(eval-after-load "ansi-term"
'(define-key ansi-term-raw-map (kbd "C-c C-y") 'term-paste))
I enabled xterm-mouse-mode, after that I was able to select text using mouse and copy using standard Mac command C button in ansi-term in emacs GUI in Mac OS X,
I have the following emacs lisp snippet that will launch my browser from within emacs and open the specified pages. However when I run it as a script from a shell nothing happens. What more do I need to do? I tried dropping (interactive).
#!/usr/bin/emacs --script
(defun surf-news ()
(interactive)
(progn
(browse-url "http://news.ycombinator.com")
(browse-url "http://stackoverflow.com")
))
(surf-news)
A neat function I discovered yesterday is M-x webjump which has recently been added to emacs.
As Ryan Thompson mentioned above, you can use xdg-open in Emacs.
Change:
(browse-url "http://news.ycombinator.com")
(browse-url "http://stackoverflow.com")
To:
(browse-url-xdg-open "http://news.ycombinator.com")
(browse-url-xdg-open "http://stackoverflow.com"))
I found the answer on this site, at the bottom, where it describes a Mac OS pty bug. I had to add this line and a slight delay between urls.
(setq process-connection-type nil)
Here's the complete solution.
#!/usr/bin/emacs --script
(setq process-connection-type nil);; pty's broken on the Mac
(defun surf ()
(progn
(browse-url "http://news.ycombinator.com")
(sleep-for 0.5); We need a delay
(browse-url "http://stackoverflow.com")
))
;;
;; This is what's going on behind the scenes
;;(setq url "http://www.google.com")
;;(start-process (concat "open " url) nil "open" url)
(surf)
On linux, if you are in GNOME, KDE, or probably almost any graphical environment, there is probably a command called xdg-open. This command basically takes its argument and opens it with the desktop default application. It handles both files and URLs. So generally when I need to say "Open this in the default application," I use xdg-open.
I think Mac OS has a similar command just called open.