How to customise Oh My ZSH within a Spacemacs shell? - emacs

Context
I have a nice and beautiful setup on iTerm2 (I'm using a Mac) where the default shell is ZSH and it is properly customized using Oh-my-zsh and the Agnoster-fcamblor Theme.
Issue
As a Spacemacs user, I would like to do as much as possible without leaving Emacs. So I decided to invoke a terminal window from inside of it, as I'm used to doing with Vim/tmux.
This is the look that I get (in the same directory):
Things I've checked
Apparently the Theme is not being applied.
This is the relevant part of my ~/.spacemacs:
(shell :variables
shell-default-shell 'ansi-term
shell-default-height 30
shell-default-term-shell "/bin/zsh"
shell-default-position 'bottom)
A few important things:
$> echo $0 shows me ZSH is the shell being used inside Spacemacs.
$> echo $PS1 shows me it is properly set and it matches iTerm2.
I tried sourcing the configuration file I use but, as the above fact suggests, it is already being loaded.
Question
How can I apply the Oh-my-zsh Theme inside a Spacemacs Shell Window?

Instead of trying to make Spacemacs options override the terminal options (wasn't able to do it), I decided to match the Spacemacs Theme with the Agnoster-Fcamblor theme I've been using, this way both have the same colors and backgrounds (a.k.a. skin/theme).
1. Inside dotspacemacs-additional-packages:
color-theme-solarized
2. Inside dotspacemacs/user-config:
(defun dotspacemacs/user-config ()
;; Fix separators
(setq ns-use-srgb-colorspace nil)
;; (setq powerline-default-separator 'utf-8)
;; Theme Customizations
(setq theming-modifications
'((solarized
;; Provide a sort of "on-off" modeline whereby the current buffer has a nice
;; bright blue background, and all the others are in cream.
;; TODO: Change to use variables here. However, got error:
;; (Spacemacs) Error in dotspacemacs/user-config: Wrong type argument: stringp, pd-blue
(mode-line :foreground "#e9e2cb" :background "#2075c7" :inverse-video nil)
(powerline-active1 :foreground "#e9e2cb" :background "#2075c7" :inverse-video nil)
(powerline-active2 :foreground "#e9e2cb" :background "#2075c7" :inverse-video nil)
(mode-line-inactive :foreground "#2075c7" :background "#e9e2cb" :inverse-video nil)
(powerline-inactive1 :foreground "#2075c7" :background "#e9e2cb" :inverse-video nil)
(powerline-inactive2 :foreground "#2075c7" :background "#e9e2cb" :inverse-video nil)
;; Make a really prominent helm selection line.
(helm-selection :foreground "white" :background "#2075c7" :inverse-video nil)
;; See comment above about dotspacemacs-colorize-cursor-according-to-state.
(cursor :background "#b58900")
)))

Related

Current line highlight (hl-line) does not respect existing highlights

I am trying to configure hl-line or hl-line+ in emacs to respect the existing highlights/text background colors in the buffer.
I have configured hl-line in ~/.emacs as follows:
(require 'hl-line)
(global-hl-line-mode 1)
Then I highlight the symbol at point using highlight-symbol-at-point (M-s h .). This highlights the symbol under the cursor all over the buffer with a yellow background.
However, when I move the cursor over a line containing that symbol, the hl-line overlay hides the yellow background. My expectation would be for the line to be highlighted, but for the yellow background to be respected.
After doing some digging, I also tried with the hl-line+ package as it has an overlay priority option that sounds promising. I downloaded the hl-line+.el file and setup my ~/.emacs as follows:
(add-to-list 'load-path (expand-file-name "~/.emacs.d/packages/hl-line+/"))
(require 'hl-line+)
(global-hl-line-mode 1)
(setq-default hl-line-overlay-priority -100)
However, this still has the same incorrect behivour to hide the existing yellow background.
Anybody knows how to configure either of these packages to respect the existing background colors?
highlight-symbol uses font-lock, which adds text properties (face or font-lock-face) to chars in the buffer.
Overlay properties (including face and `font-lock-face) are not applied to chars in the buffer. They're applied to buffer positions. They "overlay" the buffer contents; they're not part of the buffer contents.
Overlay properties always take priority over text properties. This means overlay highlighting always overrides text-property highlighting (e.g. by font-lock).
Overlay priorities only specify the relative priority among overlays. Again, any overlay highlighting overrides any text-property highlighting.
So I think the answer is that you can't do what you request. (Someone else will correct me, if there's a way around this.)
Reading the hi-lock.el documentation, this explanation stood out:
"In buffers where Font Lock mode is enabled, patterns are highlighted
using font lock. In buffers where Font Lock mode is disabled,
patterns are applied using overlays"
So as it turns out, the hi-lock.el package is able to highlight using overlays, but only when font lock mode is disabled. I tested this by disabling font lock with M-x font-lock-mode, and I can confirm the highlighting is now properly displayed when also highlighting the current line with hl-line. The problem is that all language syntax highlighting is now gone, so this option is no good.
If anybody knows how to configure hi-lock.el to use overlays with font-lock-mode enabled, then that would be the best answer.
In the meantime, there is an alternative MELPA package that supports overlay highlighting, and it woks like a charm with hl-line: symbol-overlay.el.
Having said that, I am not too fond of default key bindings and highlighting colors. For reference I leave here my configuration:
(require 'symbol-overlay)
(global-set-key (kbd "<f2>") 'symbol-overlay-jump-next)
(global-set-key (kbd "S-<f2>") 'symbol-overlay-jump-prev)
(global-set-key (kbd "C-<f2>") 'symbol-overlay-put)
(global-set-key (kbd "M-<f2>") 'symbol-overlay-query-replace)
(global-set-key (kbd "<f7>") 'symbol-overlay-mode)
(global-set-key (kbd "<f8>") 'symbol-overlay-remove-all)
(set-face-attribute 'symbol-overlay-default-face nil :background "coral1" :foreground "black")
(set-face-attribute 'symbol-overlay-face-1 nil :background "gold2" :foreground "black")
(set-face-attribute 'symbol-overlay-face-2 nil :background "chocolate2" :foreground "black")
(set-face-attribute 'symbol-overlay-face-3 nil :background "PaleGreen2" :foreground "black")
(set-face-attribute 'symbol-overlay-face-4 nil :background "SkyBlue2" :foreground "black")
(set-face-attribute 'symbol-overlay-face-5 nil :background "PaleVioletRed2" :foreground "black")
(set-face-attribute 'symbol-overlay-face-6 nil :background "IndianRed2" :foreground "black")
(set-face-attribute 'symbol-overlay-face-7 nil :background "PaleTurquoise2" :foreground "black")
(set-face-attribute 'symbol-overlay-face-8 nil :background "MediumOrchid2" :foreground "black")

how does emacs choose which script to initialize with?

In both emacs 25.2.2 on Ubuntu 18.10, and 26.2 on arch we are experiencing the following weird behavior:
Ubuntu 18:
there is a .emacs file in my home directory.
If I run emacs, it works
.emacs sets indent style, font, and color
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((t (:inherit nil :stipple nil :background "white" :foreground "black" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight bold :height 180 :width normal :foundry "urw" :family "Nimbus Mono L")))))
(set-background-color "black")
(set-foreground-color "green")
When emacs is run by gnome-settings, it does not set the font correctly, but does set the indent and the color. I therefore conclude that the font setting is not working when gnome is first set up.
On arch, running emacs looks ok. But then if we load the file and M-x eval-buffer the font changes. Evaluating twice changes the font again. Eval a third time does nothing.
Can anyone explain what is happening, and how we can reliably select a font regardless of when the command is run?

how to unset the foreground color of whitespace-mode for Emacs

In programming files, I use whitespace-mode to highlight the tab and long lines. The default highlighting is too garnish for me.I just want to highlight them with a gray background and keep whatever normal color it should be for the font. How could I set that?
The following setup does not work. I'd like the code beyond 80 columns appearing yellowish, as the characters inside 80 columns in the snapshot.
;; face for long lines' tails
(set-face-attribute 'whitespace-line nil
:background "#555"
:weight 'bold)
;; face for Tabs
(set-face-attribute 'whitespace-tab nil
:background "#555"
:weight 'bold)
set-face-attribute changes only the attributes you specify.
Set :foreground to nil:
(set-face-attribute 'whitespace-line nil
:foreground nil
:background "#555"
:weight 'bold)
For me the unpleasant color turned out to be trailing-whitespace and I'm using this:
;; whitepace looks rediculous in color themes.
(defadvice color-theme-install (after my-color-theme-install-after activate)
"Fix trailing-whitespace after color theme destroys it"
(set-face-attribute 'trailing-whitespace nil
:foreground 'unspecified
:inverse-video 'unspecified
:slant 'unspecified
:weight 'unspecified
:background "#fff"))

Emacs customize-face loses/fails to recognise font-name it wrote to my .emacs itself

I used the Options/Set Default Font menu item to set my default emacs font to be LMMonoLtCond10 (it brought up a nice font-selector GUI widget to let me do this). My emacs immediately adopted the new font, and I was very happy. I then did Options/Save Options, and on inspecting my .emacs.d/init.el file saw that it had written the following there:
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((t (:inherit nil :stipple nil :background "white" :foreground "black"
:inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal
:weight light :height 120 :width normal :foundry "unknown" :family "LMMonoLtCond10"))))
(There are a couple of other faces I've defined below that.)
Unfortunately, if I quit emacs, and restart, it completely fails to recreate the font configuration that I had selected. Instead, I think it's giving me LMRoman-12. Am I doing something wrong, or is this an emacs bug.
I'm using Emacs 23.1.1:
(emacs-version)
"GNU Emacs 23.1.1 (i486-pc-linux-gnu, GTK+ Version 2.20.1)
of 2011-03-05 on palmer, modified by Debian"
on an Ubuntu system.
Sounds like it might be a bug. M-x report-emacs-bug

emacsclient unable to load color "unspecified-bg"

I'm getting the error Unable to load color "unspecified-bg" [16 times] when using emacsclient -c. I've started up emacs using emacs --daemon. This seems to mean that my custom faces won't load.
When starting emacs as usual, and then using M-x server-start, then this problem doesn't happen at all. How can I get emacsclient -c to load the faces properly?
Here's the relevant code:
(custom-set-faces '(default ((t (:inherit nil :stipple nil :background "black" :foreground "white" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 120 :width normal :foundry "unknown" :family "Inconsolata")))))
I'm not 100% sure this would fix your problem, but you really should be using color-theme for syntax highlighting. Custom is meant for beginning emacs users, so I'd suggest you try out color-theme and see if it works. Here's how I have it set up on my machine:
Download the package from the color-theme homepage.
Put the color-theme folder somewhere like ~/.emacs.d/color-theme/.
Make sure this folder is in your load-path. I took the following code from a Steve Yegge post:
In your .emacs:
(defvar emacs-root "~/.emacs.d/")
(labels
((add-path
(p)
(add-to-list
'load-path
(concat emacs-root p))))
(add-path "lisp")
(add-path "color-theme-6.6.0")
(add-path "cedet-1.0"))
(require 'color-theme)
Then you define your color theme:
;; Color-theme
(eval-after-load "color-theme"
'(progn
(color-theme-initialize)
;; Set custom color theme
(defun color-theme-mine ()
"My custom color theme"
(interactive)
(set-cursor-color "#ffffff")
(color-theme-install
'(color-theme-mine
;; Super-light grey on Dark grey
((foreground-color . "#e0e0e0")
(background-color . "#151515")
(background-mode . dark))
(font-lock-comment-face ((t (:foreground "#106010")))) ;; Forest Green
;; More definitions below
;; ...
(color-theme-mine)) ;; end eval-after-load
This will load color-them-mine when you start emacs. You can see all available color themes by typing M-x color-theme <TAB>. To see the full list of faces available, use the command M-x list-faces-display.
Sounds like this might be bug #4776: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=4776#5. If not, consider filing a bug report for this one, using M-x report-emacs-bug.