rougier / nano-emacs

GNU Emacs / N Λ N O - Emacs made simple
GNU General Public License v3.0
2.52k stars 194 forks source link

Nano and helm? #64

Closed ndw closed 3 years ago

ndw commented 3 years ago

I'm trying a little harder to build a configuration on top of nano. Mostly because I want to try out the mu4e customization, but also because I expect almost thirty years of emacs hacking has, uh, bloated things a little. I wondered what it would be like to try nano and add just the things I need.

One of the things I've gotten used to is helm. But if I load helm and nano, I get invalid face messages.

Here's my pared down config:

;; Can't use straight to load nano-emacs because it compiles
;; nano-layout.elc and https://github.com/rougier/nano-emacs/issues/28

(add-to-list 'load-path "~/.emacs.d/personal/nano-emacs")
(require 'nano-faces)
(require 'nano-layout)
(require 'nano-theme)
(require 'nano-theme-dark)
(require 'nano-theme-light)
(require 'nano-splash)
(require 'nano-modeline)

;;; Define Nano dark & light theme functions

(defun nano-theme-dark ()
  "Enable dark Nano theme and customizations."
  (interactive)
  (nano-theme-set-dark)
  (nano-faces)
  (nano-theme)
  ;; Fall back font for glyph missing in Roboto
  (defface fallback '((t :family "Fira Code"
                         :inherit 'nano-face-faded)) "Fallback")
  (set-display-table-slot standard-display-table 'truncation
                          (make-glyph-code ?… 'fallback))
  (set-display-table-slot standard-display-table 'wrap
                          (make-glyph-code ?↩ 'fallback)))

(defun nano-theme-light ()
  "Enable light Nano theme and customizations."
  (interactive)
  (nano-theme-set-light)
  (nano-faces)
  (nano-theme)
  ;; Fall back font for glyph missing in Roboto
  (defface fallback '((t :family "Fira Code"
                         :inherit 'nano-face-faded)) "Fallback")
  (set-display-table-slot standard-display-table 'truncation
                          (make-glyph-code ?… 'fallback))
  (set-display-table-slot standard-display-table 'wrap
                          (make-glyph-code ?↩ 'fallback)))

;;; Set Theme
(nano-theme-light)

;;; Provide theme for init.el
(provide 'setup-theme)

;; ============================================================

;; Remove the built-in version of Org from the load-path
;; We'll load a more modern version below...
(require 'cl-seq)
(setq load-path
      (cl-remove-if
       (lambda (x)
         (string-match-p "org$" x))
       load-path))

;; Bootstrap straight.el
(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

;; Load the straight.el version of use-package
(defvar straight-use-package-by-default)
(straight-use-package 'use-package)

;; Tell straight to use use-package by default
(setq straight-use-package-by-default t)

;; Tell straight to use ssh by default, instead of https.
(setq straight-vc-git-default-protocol 'ssh)

;; ============================================================
;;
;;(setq ndw/org-local-build "/Users/ndw/Projects/emacs/org-mode/lisp")
;;(setq ndw/org-local-build nil)
;;(if (and ndw/org-local-build (file-directory-p ndw/org-local-build))
;;    (add-to-list 'load-path ndw/org-local-build)
;;  (use-package org-plus-contrib
;;    :mode (("\\.org$" . org-mode))))
;;
;; ============================================================

(use-package helm
  :init
  (setq helm-split-window-inside-p            t
        helm-move-to-line-cycle-in-source     t
        helm-ff-search-library-in-sexp        t
        helm-scroll-amount                    8
        helm-ff-file-name-history-use-recentf t)
  ;; Remove helm-source-info-cl which I don't seem to have
  (setq helm-info-default-sources
        '(helm-source-info-elisp
          helm-source-info-eieio
          helm-source-info-pages))
  :bind (("<f1>" .      helm-resume)
;         ("<f2>" .      helm-execute-kmacro)
         ("C-," .       helm-calcul-expression)
         ("C-:" .       helm-eval-expression-with-eldoc)
         ("C-c <SPC>" . helm-all-mark-rings)
         ("C-c f" .     helm-recentf)
         ("C-c g" .     helm-gid)
         ("C-c i" .     helm-imenu)
         ("C-c I" .     helm-imenu-in-all-buffers)
         ("C-h C-s" .   helm-occur)
         ("C-h a" .     helm-apropos)
         ("C-h f" .     helm-find)
         ("C-h g" .     helm-google-suggest)
         ("C-h i" .     helm-info-at-point)
         ("C-h r" .     helm-info-emacs)
;         ("C-h s" .     helm-swoop)
         ("C-x C-d" .   helm-browse-project)
         ("C-x C-f" .   helm-find-files)
         ("C-x b" .     helm-mini)
;         ("C-x r b" .   helm-filtered-bookmarks)
;         ("C-x c b" .   helm-chrome-bookmarks)
         ("M-x" .       helm-M-x)
         ("M-y" .       helm-show-kill-ring)
         ("M-g a" .     helm-do-grep-ag)
         ([remap jump-to-register] . helm-register)
         ([remap list-buffers]     . helm-buffers-list)
         ([remap dabbrev-expand]   . helm-dabbrev)
         ([remap find-tag]         . helm-etags-select)
         ([remap xref-find-definitions] . helm-etags-select))
)

;; ============================================================

With (just) this in my init.el, I get an invalid face (helm-swoop-target-line-face) as soon as I do anything that tries to prompt in the minibuffer.

With this configuration I can't even get a stack trace to occur, but I did with a slightly less minimal configuration and it was falling over in the with-eval-after-load 'helm code in nano-theme.el, I believe.

rougier commented 3 years ago

I'm not using helm so I'm not sure what is the problem. Starting with this configuration and if you remove anything nano related, does it work as expected? If yes, can you start adding nano files one by one to check which one is faulty?

mclearc commented 3 years ago

I found I had to add helm faces in a specific way (note the various functions) though haven't tested this lately, but you might give it a try first (put this in nano-theme.el):

(defun nano-theme--helm ()
  "Derive helm faces from nano faces."
  (with-eval-after-load 'helm
    (set-face 'helm-selection                '(nano-face-strong nano-face-subtle))
    (set-face 'helm-match                                       'nano-face-strong)
    (set-face 'helm-source-header                              'nano-face-salient)
    (set-face 'helm-visible-mark                                'nano-face-strong)))

(defun nano-theme--helm-swoop ()
  "Derive helm faces from nano faces."
  (with-eval-after-load 'helm-swoop
    (set-face 'helm-swoop-target-line-face   '(nano-face-strong nano-face-subtle))))

(defun nano-theme--helm-occur ()
  "Derive helm faces from nano faces."
  (with-eval-after-load 'helm-occur
    (set-face 'helm-moccur-buffer                               'nano-face-strong)))

(defun nano-theme--helm-ff ()
  "Derive helm faces from nano faces."
  (with-eval-after-load 'helm-ff
    (set-face 'helm-ff-file                                      'nano-face-faded)
    (set-face 'helm-ff-prefix                                   'nano-face-strong)
    (set-face 'helm-ff-dotted-directory                          'nano-face-faded)
    (set-face 'helm-ff-directory                                'nano-face-strong)
    (set-face 'helm-ff-executable                               'nano-face-popout)))

(defun nano-theme--helm-grep ()
  "Derive helm faces from nano faces."
  (with-eval-after-load 'helm-grep
    (set-face 'helm-grep-match                                  'nano-face-strong)
    (set-face 'helm-grep-file                                    'nano-face-faded)
    (set-face 'helm-grep-lineno                                  'nano-face-faded)
    (set-face 'helm-grep-finish                                'nano-face-default)))
rougier commented 3 years ago

By the way, for the mu4e customization, you don't need to use nano at all. You can only use the nano-mu4e.el and adapt the few faces that are required (only four I think).

For the helm problem, the culprit seems to be helm-swoop, is that right? if yes, I can have a look at the code to see if I can find something strange inside.

mclearc commented 3 years ago

If I'm remembering correctly, the problem is that helm-swoop (and other parts of helm) are not all loaded when helm itself is, so the single with-eval-after-load call isn't enough. Hence the separate loading of helm parts as described above.

rougier commented 3 years ago

You mean the above init splitting works as intended ? If so, can you make a PR?

ndw commented 3 years ago

Thanks, @mclearc that did the trick. I'll make a PR, since I've got it "right here".