passing escape sequences from tmux to gnu screen - emacs

For practical reasons, I am using tmux inside gnu screen (*).
Inside tmux, I have emacs, so far, everything is running well: fonts, characters, colours, etc.
Only one thing does not work with this configuration: changing the cursor shape, using the VTE escape sequences. If I use emacs inside tmux only, it works. If I use emacs in the terminal only, it works too.
I used the following code in the tmux.conf file:
set-option -ga terminal-overrides ",tmux-256color:Se=\\E[0 q"
set-option -ga terminal-overrides ",tmux-256color:Se=\\E[1 q"
set-option -ga terminal-overrides ",tmux-256color:Se=\\E[2 q"
set-option -ga terminal-overrides ",tmux-256color:Se=\\E[3 q"
set-option -ga terminal-overrides ",tmux-256color:Se=\\E[4 q"
set-option -ga terminal-overrides ",tmux-256color:Se=\\E[5 q"
set-option -ga terminal-overrides ",tmux-256color:Se=\\E[6 q"
And inside emacs:
;; Change the cursor shape according to the mode, in VTE based terminals
(add-hook 'overwrite-mode-hook
(lambda ()
(if overwrite-mode (send-string-to-terminal "\033[3 q")
(send-string-to-terminal "\033[5 q"))
)
)
(add-hook 'read-only-mode-hook
(lambda ()
(if buffer-read-only (send-string-to-terminal "\033[2 q")
(send-string-to-terminal "\033[5 q"))
)
)
So far, everything is working as expected. When I switch to overwrite mode, the cursor shape change into the terminal. However, if I run tmux inside screen, it does not work any more.
Can you tell me what I have to add to screen - or tmux configuration to make this working.
Thanks.
I need to remotely connect on multiple servers at once in one terminal, ant tmux inside screen is the most practical option. Especially since each of the remote servers runs tmux...

Related

Emacs: "C-x #" killing buffer

I've been searching for an answer to this issue, I found
Emacs Client: difference between C-x k and C-x #
and
Emacs C-x C-c overriding save-buffers-kill-terminal if within last open frame
but it not exactly related. Here's the issue:
I have emacs started as a daemon and use emacsclient to connect to it.
I primary use emacsclient inside the OS X terminal with the -nw option.
The specfic command i use is:
/Applications/Emacs.app/Contents/MacOS/bin/emacsclient /tmp/foo -nw -c -s /tmp/emacs501/work_guigo
So I have two files in /tmp/, named foo and baa.
In my terminal.app, I open foo with
/Applications/Emacs.app/Contents/MacOS/bin/emacsclient /tmp/foo -nw -c -s /tmp/emacs501/work_guigo
Emacs tells me, "When done with a buffer, type C-x #", so I do that.
I'm done with it for now, but I'm not done with it for today, so I want the foo file to remain in my "C-x b" buffers list.
So I'm back in the terminal, I open baa with
/Applications/Emacs.app/Contents/MacOS/bin/emacsclient /tmp/baa -nw -c -s /tmp/emacs501/work_guigo
Now when I do a C-x b, I don't see foo in the list of open buffers.
This sucks. What should I do?
---some additional info:
emacs 24.5
using helm for "C-x b"
Sometimes, I find the answer to my own question.
In this case, it was a matter of having
(setq server-kill-new-buffers nil)
near the top of the init.el

What Eshell's equivalent command for the shell command Ctrl-U?

In Terminal, I can erase the entire input by Ctrl-U, without invoke it. Is there such a command in Eshell?
You're looking for eshell-kill-input, which is bound to C-c C-u by default.
I don't think that eshell natively supports killing the entire input string (it only kills the text between point and the prompt), but some advice should take care of that:
;;; For Emacs 24.4 and later
(defun eshell-kill-input--go-to-eol ()
"Go to end of line before killing input"
(end-of-line))
(advice-add 'eshell-kill-input :before #'eshell-kill-input--go-to-eol)
;;; For Emacs versions before 24.4
(defadvice eshell-kill-input (before go-to-eol ())
"Go to end of line before killing input"
(end-of-line))

Space character inside an argument (emacs lisp)

In windows, I set the variable inferior-lisp-program to be (shell-quote-argument "D:/Program Files/ccl/wx86cl.exe").
But when I run inferior lisp with the command run-lisp, emacs responds:
Searching for program: no such file or directory, "D:/Program
It seemed that emacs treats "D:/Program Files/ccl/wx86cl.exe" as two arguments "D:/Program and Files/ccl/wx86cl.exe" separated by a space character.
How can I make emacs treat "D:/Program Files/ccl/wx86cl.exe" as a whole?
Try using the old "Progra~1" compatibility name for "Program Files". So,
(setq inferior-lisp-program "D:/Progra~1/ccl/wx86cl.exe")

I want to run the cygwin bash shell from native windows emacs app

I have followed instructions from How can I run Cygwin Bash Shell from within Emacs? this question and I have gone further and added the (setq explicit-bash-args '("--login" "-i")) command, however emacs continues to only display the dos prompt when I type M-x shell. In summery my .emacs file looks like this:
(defun cygwin-shell ()
"Run cygwin bash in shell mode."
(interactive)
(let ((explicit-shell-file-name "C:/cygwin/bin/bash"))
(call-interactively 'shell)))
(setq explicit-bash-args '("--login" "-i"))`
Please be gentle with the answers as I am right at the bottom of the famous vertical emacs learning curve!
If you implemented the answer from that question, note that you have to do M-x cygwin-shell to start bash. If you want to use it for every M-x shell you need to call
(setq explicit-shell-file-name "C:/cygwin/bin/bash")
Since you stated that you are learning, here's a few tips when trying this out.
type C-x C-f ~/.emacs to open your .emacs file in your user path.
Enter your function above at the end
M-x load-file [RET] .emacs: loads the buffer (no need to restart emacs)
C-h a: If you are interested in some specific action, you can look it up
C-h v [RET] variable: can inspect the variable, check the value of explicit-bash-args for instance
And, btw, I'm not sure what the "--login -i" does, but someone stated in a comment that you should have that so "ls" would work. If you have your cygwin bin path in your PATH environment variable, bash will find ls anyway. No need to escape the path variable either, this is handled by bash (do an echo $PATH in bash when you get it working and you'll see).

Emacs + Synctex + Skim: How to correctly set up synchronization? [none of the existing methods worked properly]

I'm working with GNU Emacs 23.3 (9.0) on Mac OS X 10.7.2. I would like to use synctex to jump between .tex and .pdf files. Although there are many different approaches on the web, none worked properly (I tried 8 different approaches...). I finally ended up with the rather simple approach described here: http://sourceforge.net/apps/mediawiki/skim-app/index.php?title=TeX_and_PDF_Synchronization
So my .emacs contains:
'(LaTeX-command "latex -synctex=1")
(require 'tex-site)
(add-hook 'TeX-mode-hook
(lambda ()
(add-to-list 'TeX-output-view-style
'("^pdf$" "."
"/Applications/Skim.app/Contents/SharedSupport/displayline -b %n %o %b")))
)
(server-start)
Of course, I also set up Skim (Preferences -> Sync -> checked "Check for file changes" and chose Preset: Emacs with command emacsclient and arguments --no-wait +%line "%file")
As you can see, I included the -b option to displayline. I can call displayline from the terminal and it opens the .pdf and displays the corresponding line with a yellow/highlighted bar. Still, nothing is displayed on the current line if I compile the document with latexmk -pvc -pdf from a shell within Emacs.app.
Question 1: How can I get this to work/How can I display the current line?
Question 2: Is it possible to have a "proper" forward search by clicking the .tex and jumping to the corresponding line in the .pdf document? How can I "click" in emacs? The standard CMD + shift + click does not work in emacs.
I also tried approaches using...
(setq TeX-source-correlate-method 'synctex)
(add-hook 'LaTeX-mode-hook 'TeX-source-correlate-mode)
... but nothing changes.
I can CMD + shift + click in the .pdf and jump to the .tex, so that works.
The only directions which I haven't looked into are:
is this a latexmk problem? Most likely not, since latexmk explicitly displays pdflatex -interaction=nonstopmode -synctex=1 so synctex is recognized
is it a wrong skim preference setting? Maybe I have to adjust the arguments to emacsclient there (?)
Solution
Indeed latexmk is the problem. I finally figured out the following settings:
~/.emacs
;; make latexmk available via C-c C-c
;; Note: SyncTeX is setup via ~/.latexmkrc (see below)
(add-hook 'LaTeX-mode-hook (lambda ()
(push
'("latexmk" "latexmk -pdf %s" TeX-run-TeX nil t
:help "Run latexmk on file")
TeX-command-list)))
(add-hook 'TeX-mode-hook '(lambda () (setq TeX-command-default "latexmk")))
;; use Skim as default pdf viewer
;; Skim's displayline is used for forward search (from .tex to .pdf)
;; option -b highlights the current line; option -g opens Skim in the background
(setq TeX-view-program-selection '((output-pdf "PDF Viewer")))
(setq TeX-view-program-list
'(("PDF Viewer" "/Applications/Skim.app/Contents/SharedSupport/displayline -b -g %n %o %b")))
(server-start); start emacs in server mode so that skim can talk to it
~/.latexmkrc
$pdflatex = 'pdflatex -interaction=nonstopmode -synctex=1 %O %S';
$pdf_previewer = 'open -a skim';
$clean_ext = 'bbl rel %R-blx.bib %R.synctex.gz';
This perfectly allows to compile with latexmk as default on C-c C-c and C-c C-v opens Skim at the current line which is nicely highlighted. With CMD + shift + click in the .pdf, one can then jump back to the corresponding paragraph in the .tex file (thanks to server-start).
To enable the clicking feature of the sync, I added:
(add-hook 'LaTeX-mode-hook
(lambda () (local-set-key (kbd "<S-s-mouse-1>") #'TeX-view))
)
to my .emacs file.
NOTE: make sure that you are in PDF mode (use (setq TeX-PDF-mode t)).
When you press C-c C-v (which runs TeX-view) it should open Skim with the bar on the current line. This is what you set up with the TeX-output-view-style. You can't get that behaviour from latexmk -pvc since it doesn't know which line you are on. All latexmk knows is that the file changed. In order to do a forward search you need to run TeX-view.
You can bind CMD + shift + click to run TeX-view by adding
(define-key LaTeX-mode-map [M-S-mouse-1] 'TeX-view)
or possibly
(define-key LaTeX-mode-map [s-S-mouse-1] 'TeX-view)
to your TeX-mode-hook. It depends on your settings which you need, but can find out by pressing C-h C-k and then CMD+shift+click. Of course adding both shouldn't cause a problem.