rougier / nano-emacs

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

Can't change the font #35

Closed brunomiguel closed 3 years ago

brunomiguel commented 3 years ago

As requested on Reddit, I'm opening a bug report because I can't change the face used by nano-emacs to Fira Mono

I've cloned the repo to $HOME/.emacs.d, created a nano folder inside .emacs.d and moved all the nano-*.el files to it, except for nano.el that was kept in the root emacs config dir. After that, I renamed nano.el to init.el, changed the load files path to the correct dir and commented the last line:

;; ---------------------------------------------------------------------
;; GNU Emacs / N Λ N O - Emacs made simple
;; Copyright (C) 2020 - N Λ N O developers
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;; ---------------------------------------------------------------------
(package-initialize)

;; Path to nano emacs modules (mandatory)
(add-to-list 'load-path "/home/brunomiguel/.emacs.d/nano")
;; (add-to-list 'load-path ".")

;; Window layout (optional)
(require 'nano-layout)

;; Theming Command line options (this will cancel warning messages)
(add-to-list 'command-switch-alist '("-dark"   . (lambda (args))))
(add-to-list 'command-switch-alist '("-light"  . (lambda (args))))
(add-to-list 'command-switch-alist '("-default"  . (lambda (args))))

(cond
 ((member "-default" command-line-args) t)
 ((member "-dark" command-line-args) (require 'nano-theme-dark))
 (t (require 'nano-theme-light)))

;; Customize support for 'emacs -q' (Optional)
;; You can enable customizations by creating the nano-custom.el file
;; with e.g. `touch nano-custom.el` in the folder containing this file.
(let* ((this-file  (or load-file-name (buffer-file-name)))
       (this-dir  (file-name-directory this-file))
       (custom-path  (concat this-dir "nano-custom.el")))
  (when (and (eq nil user-init-file)
             (eq nil custom-file)
             (file-exists-p custom-path))
    (setq user-init-file this-file)
    (setq custom-file custom-path)
    (load custom-file)))

;; Theme
(require 'nano-faces)
(nano-faces)

(require 'nano-theme)
(nano-theme)

;; Nano default settings (optional)
(require 'nano-defaults)

;; Nano session saving (optional)
(require 'nano-session)

;; Nano header & mode lines (optional)
(require 'nano-modeline)

;; Nano key bindings modification (optional)
(require 'nano-bindings)

;; Nano counsel configuration (optional)
;; Needs "counsel" package to be installed (M-x: package-install)
;; (require 'nano-counsel)

;; Welcome message (optional)
(let ((inhibit-message t))
  (message "Welcome to GNU Emacs / N Λ N O edition")
  (message (format "Initialization time: %s" (emacs-init-time))))

;; Splash (optional)
(add-to-list 'command-switch-alist '("-no-splash" . (lambda (args))))
(unless (member "-no-splash" command-line-args)
  (require 'nano-splash))

;; Help (optional)
(add-to-list 'command-switch-alist '("-no-help" . (lambda (args))))
(unless (member "-no-help" command-line-args)
  (require 'nano-help))

;; (provide 'nano)

In nano-faces.el, I have this:

;;; nano-faces --- Face settings for nano-emacs
;;; License:
;; ---------------------------------------------------------------------
;; GNU Emacs / N Λ N O - Emacs made simple
;; Copyright (C) 2020 - N Λ N O developers
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
;; ---------------------------------------------------------------------
;;; Commentary:
;;
;; This file defines the 6 basic nano faces:
;;
;; - nano-face-critical  - nano-face-popout   - nano-face-salient
;; - nano-face-default   - nano-face-faded    - nano-face-subtle
;;
;; Several nano modules require
;;
;; ---------------------------------------------------------------------
;;; Code:

(require 'nano-base-colors)

;; A theme is fully defined by these six faces

(defface nano-face-default nil
  "Default face is used for normal information."
  :group 'nano)

(defface nano-face-critical nil
  "Critical face is for information that requires immediate action.
It should be of high constrast when compared to other faces. This
can be realized (for example) by setting an intense background
color, typically a shade of red. It must be used scarcely."
  :group 'nano)

(defface nano-face-popout nil
  "Popout face is used for information that needs attention.
To achieve such effect, the hue of the face has to be
sufficiently different from other faces such that it attracts
attention through the popout effect."
  :group 'nano)

(defface nano-face-strong nil
  "Strong face is used for information of a structural nature.
It has to be the same color as the default color and only the
weight differs by one level (e.g., light/normal or
normal/bold). IT is generally used for titles, keywords,
directory, etc."
  :group 'nano)

(defface nano-face-salient nil
  "Salient face is used for information that are important.
To suggest the information is of the same nature but important,
the face uses a different hue with approximately the same
intensity as the default face. This is typically used for links."
  :group 'nano)

(defface nano-face-faded nil
  "Faded face is for information that are less important.
It is made by using the same hue as the default but with a lesser
intensity than the default. It can be used for comments,
secondary information and also replace italic (which is generally
abused anyway)."
  :group 'nano)

(defface nano-face-subtle nil
  "Subtle face is used to suggest a physical area on the screen.
It is important to not disturb too strongly the reading of
information and this can be made by setting a very light
background color that is barely perceptible."
  :group 'nano)

(defface nano-face-header-default nil
  "Default face for ther header line."
  :group 'nano)

(defface nano-face-header-critical nil
  "Critical face for ther header line."
  :group 'nano)

(defface nano-face-header-popout nil
  "Popout face for ther header line."
  :group 'nano)

(defface nano-face-header-strong nil
  "Strong face for ther header line."
  :group 'nano)

(defface nano-face-header-salient nil
  "Salient face for ther header line."
  :group 'nano)

(defface nano-face-header-faded nil
  "Faded face for ther header line."
  :group 'nano)

(defface nano-face-header-subtle nil
  "Subtle face for ther header line."
  :group 'nano)

(defface nano-face-header-highlight nil
  "Highlight face for ther header line."
  :group 'nano)

(defface nano-face-header-separator nil
  "Face for separating item in the header line (internal use)"
  :group 'nano)

(defface nano-face-header-filler nil
  "Face compsenting spaces in the header line (internal use) "
  :group 'nano)

(defface nano-face-tag-default nil
  "Default face for tags"
  :group 'nano)

(defface nano-face-tag-faded nil
  "Faded face for tags"
  :group 'nano)

(defface nano-face-tag-strong nil
  "Strong face for tags"
  :group 'nano)

(defface nano-face-tag-salient nil
  "Salient face for tags"
  :group 'nano)

(defface nano-face-tag-popout nil
  "Popout face for tags"
  :group 'nano)

(defface nano-face-tag-critical nil
  "Critical face for tags"
  :group 'nano)

(defun nano-what-faces (pos)
  "Get the font faces at POS."
  (interactive "d")
  (let ((faces (remq nil
                     (list
                      (get-char-property pos 'read-face-name)
                      (get-char-property pos 'face)
                      (plist-get (text-properties-at pos) 'face)))))
    (message "Faces: %s" faces)))

(defun nano-faces ()
  "Derive face attributes for nano-faces using nano-theme values."
  (set-face-attribute 'nano-face-default nil
                      :foreground nano-color-foreground
                      :background nano-color-background)
  (set-face-attribute 'nano-face-critical nil
                      :foreground nano-color-foreground
                      :background nano-color-critical)
  (set-face-attribute 'nano-face-popout nil
                      :foreground nano-color-popout)

  (if (display-graphic-p)
      (set-face-attribute 'nano-face-strong nil
                          :foreground (face-foreground 'nano-face-default)
                          :family "Fira Mono"
                          :weight 'medium)
    (set-face-attribute 'nano-face-strong nil
                        :foreground (face-foreground 'nano-face-default)
                        :weight 'bold))

  (set-face-attribute 'nano-face-salient nil
                      :foreground nano-color-salient
                      :weight 'light)

  (set-face-attribute 'nano-face-faded nil
                      :foreground nano-color-faded
                      :weight 'light)

  (set-face-attribute 'nano-face-subtle nil
                      :background nano-color-subtle)

  (set-face-attribute 'nano-face-header-default nil
                      :foreground nano-color-foreground
                      :background nano-color-subtle
                      :box `(:line-width 1
                                         :color ,nano-color-background
                                         :style nil))

  (set-face-attribute 'nano-face-tag-default nil
                      :foreground nano-color-foreground
                      :background nano-color-background
                      :family "Fira Mono" :weight 'normal
                      :height (if (display-graphic-p) 120 1)
                      :box `(:line-width 1
                                         :color ,nano-color-foreground
                                         :style nil))

  (set-face-attribute 'nano-face-header-strong nil
                      :foreground nano-color-strong
                      :background nano-color-subtle
                      :inherit 'nano-face-strong
                      :box `(:line-width 1
                                         :color ,nano-color-background
                                         :style nil))

  (set-face-attribute 'nano-face-tag-strong nil
                      :foreground nano-color-strong
                      :background nano-color-subtle
                      :family "Fira Mono" :weight 'normal
                      :height (if (display-graphic-p) 120 1)
                      :box `(:line-width 1
                                         :color ,nano-color-strong
                                         :style nil))

  (set-face-attribute 'nano-face-header-salient nil
                      :foreground nano-color-background
                      :background nano-color-salient
                      :box `(:line-width 1
                                         :color ,nano-color-background
                                         :style nil))

  (set-face-attribute 'nano-face-tag-salient nil
                      :foreground nano-color-background
                      :background nano-color-salient
                      :family "Fira Mono" :weight 'normal
                      :height (if (display-graphic-p) 120 1)
                      :box `(:line-width 1
                                         :color ,nano-color-salient
                                         :style nil))

  (set-face-attribute 'nano-face-header-popout nil
                      :foreground nano-color-background
                      :background nano-color-popout
                      :box `(:line-width 1
                                         :color ,nano-color-background
                                         :style nil))

  (set-face-attribute 'nano-face-tag-popout nil
                      :foreground nano-color-background
                      :background nano-color-popout
                      :family "Fira Mono" :weight 'normal
                      :height (if (display-graphic-p) 120 1)
                      :box `(:line-width 1
                                         :color ,nano-color-popout
                                         :style nil))

  (set-face-attribute 'nano-face-header-faded nil
                      :foreground nano-color-background
                      :background nano-color-faded
                      :box `(:line-width 1
                                         :color ,nano-color-background
                                         :style nil))

  (set-face-attribute 'nano-face-tag-faded nil
                      :foreground nano-color-background
                      :background nano-color-faded
                      :family "Fira Mono" :weight 'normal
                      :height (if (display-graphic-p) 120 1)
                      :box `(:line-width 1
                                         :color ,nano-color-faded
                                         :style nil))

  (set-face-attribute 'nano-face-header-subtle nil)

  (set-face-attribute 'nano-face-header-critical nil
                      :foreground nano-color-background
                      :background nano-color-critical
                      :box `(:line-width 1
                                         :color ,nano-color-background
                                         :style nil))
  (set-face-attribute 'nano-face-tag-critical nil
                      :foreground nano-color-background
                      :background nano-color-critical
                      :family "Fira Mono" :weight 'normal
                      :height (if (display-graphic-p) 120 1)
                      :box `(:line-width 1
                                         :color ,nano-color-critical
                                         :style nil))

  (set-face-attribute 'nano-face-header-separator nil
                      :inherit 'nano-face-default
                      :height 0.1)
  (set-face-attribute 'nano-face-header-filler nil
                      :inherit 'nano-face-header-default
                      :height 0.1)
  (set-face-attribute 'nano-face-header-highlight nil
                      :inherit 'nano-face-header-faded
                      :box nil))

(provide 'nano-faces)
;;; nano-faces.el ends here

Yet, when I start Emacs, it doesn't use Fira Mono (installed in /usr/share/fonts).

Emacs version is 27.1

rougier commented 3 years ago

The font s defined in nano-layout.el. Can you try to modify it in this file ? Plan is to have a nano-typography.elwhere you'll be able to change your font.

brunomiguel commented 3 years ago

Thank you! That fixed it.