How to set emacsclient background as Emacs background? - linux

I've got (in my .emacs)
(set-background-color "#101416")
(set-foreground-color "#f6f3e8")
And I've got 2 bindings:
alias ex='emacsclient -nw'
alias ec='emacsclient -c -a ""'
ex works fine to open client in terminal but when I want to open it as a frame I've got white background :(
Why and how can I use my dark background there?

set-background-color and set-foreground-color only affect the current frame, and your .emacs file is not executed when running emacsclient.
Try setting the variable default-frame-alist ("Alist of default values for frame creation") instead:
(setq default-frame-alist
'((background-color . "#101416")
(foreground-color . "#f6f3e8")))

Related

PuTTY: Linux window - How to update the window title during a function?

I’m accessing a Linux machine from a Windows 10 PC via PuTTY. I’ve set the PuTTY (Bash) window title to ‘$PWD’ by setting $PS1 as below:
PS1=\[\033]0;\w\007\]\[\033[1;33m\][\w]$\[\033[0m\]
This works well – whenever I change the directory in the shell, the title updates straight away:
However, if I change directory in a function (as below) the title doesn’t update until after the function completes:
function func() {
cd /share/testing_area/runtests ;
python Script.py;
}
Is there a way to get the title to update during the script?
ANSWER: Final version of the script:
function func() {
cd /share/testing_area/runtests
export PS1="\[\e[1;33m\][\w]$\[\e[0m\]" # Remove title spec from $PS1
echo -ne "\e]2;$PWD\a" # Set title to current values (uses $PWD as \w doesn't work for echo
python Script.py;
export PS1="\[\033]0;\w\007\]\[\033[1;33m\][\w]$\[\033[0m\]" # Re-add title spec to $PS1
}
You are changing the title by using PuTTY’s automatic title from the prompt. Unfortunately, the prompt will usually take effect once your prompt is visible again, which means not before your function or script ends.
If you want to change the title dynamically I would recommend this solution instead.

toggle between 2 tmux layouts

I often run Vim in a tmux session to I can run tests in an adjacent pane. On a smaller monitor, I either have to sacrifice more Vim screen real estate than I'd like, or make the test pane too small to read the full results (which is fine if everything passes, but not when there are failures and I need to see the details).
Then my workflow becomes:
trigger tests from within Vim
switch to test pane (last-pane)
zoom pane to occupy full window (resize-pane -Z)
read the results
restore original layout (resize-pane -Z)
switch back to Vim pane (last-pane)
I wanted to add a key binding that I could use when I'm in the Vim pane to zoom the test pane (hiding Vim), and be able to use the same binding once zoomed to restore the original layout, returning me to Vim. This is what I came up with, but I wonder if there's a better way I can do it. I had to set, check, and unset an environment variable to save the state that would support toggling back and forth with the same key binding. I also haven't figured out how to make the toggle state specific to a window (right now, any multi-window session shares the state across all its windows, so this doesn't work correctly)
bind Space if-shell '[ -z "${ALT_PANE_ZOOM+x}" ]' \
'select-pane -t :.+; resize-pane -Z; set-environment ALT_PANE_ZOOM 1' \
'set-environment -u ALT_PANE_ZOOM; last-pane'
Update:
I found a simpler solution. Rather than relying on a per-window environment variable, I can leverage -F and the window_zoomed_flag format variable:
bind Space if-shell -F '#{window_zoomed_flag}' \
'last-pane' \
'select-pane -t :.+; resize-pane -Z'
In your tmux.conf, create a keybind which:
Saves the zoom state
Switch to the last pane, unzooming if a pane was zoomed in
Conditionally zooms depending on the zoomed state in #1
-
bind key run-shell "tmux setenv zoomed $(tmux display -p '#{window_zoomed_flag}')"\; \
last-pane\; \
run-shell "test $(tmux display -p '#{zoomed}') -ne 0 || tmux resize-pane -Z"
Note that the backslash escapes on the semicolons command separators are required.

Setting servername in vimrc as opposed to command line switch

Is it possible to set vim's servername from my vimrc instead of using the --servername command line switch? If I try one of
set v:servername="TEX"
let v:servername="TEX"
I get unknown option error and cannot overwrite read-only variable error respectively.
According to documentation (:help v:servername) the v:servername variable is read only.
And according to source code serverRegisterName() in if_xcmdsrv.c is called from three places:
main() function
X11 main window initialization
GTK+ main window initialization
So the answer to your question is no, you can't set server name in your .vimrc or anywhere else except command line arguments.
For a sufficiently new of vim there's the function remote_startserver.
*remote_startserver()* *E941* *E942*
remote_startserver({name})
Become the server {name}. This fails if already running as a
server, when |v:servername| is not empty.
Can also be used as a |method|: >
ServerName()->remote_startserver()
Available since Vim version 8.0.475. according to VimTeX documentation
So you can simply start vim with no servername and start one in vimrc.
Note: Vim will automatically change the servername (append 1, 2, etc.) to avoid conflict if there are multiple running Vim instances.

Unwanted control characters displaying in vimscript function output

[using MacVim 7.3 on OS X Lion]
I have a vimscript function which runs an external command. It's executing correctly, but the output displays (unwanted) control characters, such as [0m, [33m, [36m, and -1H. The relevant line in the vimscript function is:
exec ":!bundle exec rspec --color " . a:filename
Which produces:
:!bundle exec rspec --color spec/acceptance/user_logs_in.feature
[33m*[0m
Pending:
[33m User logs in [0m
[36m # the step 'the user "foo#test.host" exists' is not implemented[0m
[36m # [0m
Finished in 0.07121 seconds
[33m1 example, 0 failures, 1 pending[0m
Here's what the same command and output look like from the terminal, which is how I want it to display in vim:
$ bundle exec rspec --color spec/acceptance/user_logs_in.feature
*
Pending:
User logs in
# the step 'the user "foo#test.host" exists' is not implemented
#
Finished in 0.1161 seconds
1 example, 0 failures, 1 pending
Also, any time I execute and external command, vim displays -1H immediately after it. For example, if I type:
:ls<return>
I see:
:ls-1H
<rest of the output is as expected>
Any ideas on hiding those control characters and -1H.
(disclaimer: I'm very new to vim so please don't assume too much background knowledge on my part.)
Thanks.
Update 3/31/2012 # 17:32 PM
Sam Goldman's correct: MacVim doesn't know how to display colors, so it outputs the color codes.
I've switched to terminal vim (which supports colors, at least with iTerm), but using the version of vim that comes with MacVim, which is more up-to-date and is compiled with ruby support (among other things). The easiest way to do that is:
brew install macvim --override-system-vim
MacVim doesn't know how to display colors. Terminal vim will display the colors correctly, or you can add --no-color to your rspec command (or a .rspec file). I'm not sure about the -1H thing. Maybe some customization you have for your terminal?

current directory doesn't appear in title bar when running under screen

My xterm $prompt variable in my .tcshrc is:
set prompt="%{\033]0;%m:%~\007%}%{^[[;37;1m%}%B%{^[[;34;1m%}%m%{^[[;34;1m%}:%b%c%# "
The highlighted part above (%{\033]0;%m:%~\007%}) puts the hostname (%m) and the current directory (%~) in the title bar. (At least I think that that's what puts it in the title bar; it's been a while since I fiddled with this prompt).
When I run screen, however, the current directory stops getting updated when I change directories.
My questions:
How can I make this prompt work in screen?
Is there a better way to display the current directory in the title bar?
I am running linux with xterm and tcsh.
I think there is no direct way, because of the way screen works. However screen can display its own status bar, that you can define in .screenrc. Here's mine for instance :
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%=%{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'
Firstly, to make it work you must check where exactly is the line with set prompt=blah-blah in your .tcshrc. For example, the code below that perfectly works in plain xterm would not work under screen in xterm:
switch ($TERM)
case "xterm*":
set prompt="%{\033]0;${HOME:t}#%m:%l:%c08\007%}%{\033[36m%}%l:%c02%#%{\033[0m%} "
# update xterm title to display current cmd in it
alias postcmd 'echo -n "\033]0;${HOME:t}#`hostname`:${tty} \!#:q\007"'
...
because screen by default sets $TERM variable to screen and not xterm! So you must add:
case "screen":
# lame, but prevents an error in screen after 'su - root'
if (! $?WINDOW) setenv WINDOW 1
set prompt="%{\033]0;${HOME:t}#%m:${WINDOW}:%c08\007%}%{\033[36m%}%c02%#%{\033[0m%} "
alias postcmd 'echo -n "\033]0;${HOME:t}#`hostname`:${WINDOW} \!#:q\007"'
...
Secondly, make sure yo have this line in ~/.screenrc:
termcapinfo xterm* 'hs:ts=\E]2;:fs=\007:ds=\E]2;\007'

Resources