ergoemacs / ergoemacs-mode

ergoemacs-mode
ergoemacs.github.io/
GNU General Public License v3.0
293 stars 35 forks source link

How to create a custom ergoemacs-theme #392

Closed samis closed 8 years ago

samis commented 8 years ago

I want to create a custom ergoemacs theme based on the default components, but tweaked slightly in multiple ways. It seems better to wrap these changes up in a single theme but when I attempt to define a custom ergoemacs-theme in init.el I get an error when running describe theme. The error is wrong type argument: stringp, nil.

xahlee commented 8 years ago

that means some function needs a arg of string, but got none. But that error is also common, i think some use of advice, macro, or old bytecode can also result that. maybe first try to remove all .elc files, regenerate them, and see what happens.

until matt replies with more knowledgeable specific answer.

On Mon, Dec 28, 2015 at 7:07 PM, Samuel Hodgkins notifications@github.com wrote:

I want to create a custom ergoemacs theme based on the default components, but tweaked slightly in multiple ways. It seems better to wrap these changes up in a single theme but when I attempt to define a custom ergoemacs-theme in init.el I get an error when running describe theme. The error is wrong type argument: stringp, nil.

— Reply to this email directly or view it on GitHub https://github.com/ergoemacs/ergoemacs-mode/issues/392.

mattfidler commented 8 years ago

Could you post your configuration? I won't be able to get to it to Monday.

samis commented 8 years ago

An intentionally minimal example is here. Just try to describe the created Ergoemacs theme to see the error.

mattfidler commented 8 years ago

Thanks @samis. I got the following backtrace for emacs 24.4:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  file-attributes(nil)
  (nth 5 (file-attributes file))
  (list file (nth 5 (file-attributes file)))
  (let* ((based-on (and ergoemacs-theme-hash (hash-table-p ergoemacs-theme-hash) (gethash "nil" ergoemacs-theme-hash nil))) (curr-plist (quote (:name "lvl5" :description "CUA-mode style" :components (lvl5-theme) :optional-on nil :optional-off nil :options-menu nil))) (opt-on (plist-get curr-plist (quote :optional-on))) (opt-off (plist-get curr-plist (quote :optional-off))) (comp (plist-get curr-plist (quote :components))) (themes (and ergoemacs-theme-hash (hash-table-p ergoemacs-theme-hash) (gethash "defined-themes" ergoemacs-theme-hash nil))) (silent (and ergoemacs-theme-hash (hash-table-p ergoemacs-theme-hash) (gethash "silent-themes" ergoemacs-theme-hash nil))) (included (append opt-on opt-off comp)) (file (or load-file-name (buffer-file-name))) (mod (list file (nth 5 (file-attributes file))))) (if (not (boundp (quote ergoemacs--component-file-mod-time-list))) (progn (setq ergoemacs--component-file-mod-time-list nil))) (setq themes (cons "lvl5" themes)) (setq silent (cons "lvl5" silent)) (setq curr-plist (plist-put curr-plist :file file)) (if (member mod ergoemacs--component-file-mod-time-list) nil (setq ergoemacs--component-file-mod-time-list (cons mod ergoemacs--component-file-mod-time-list))) (if (not based-on) (puthash "lvl5" curr-plist ergoemacs-theme-hash) (let ((--dolist-tail-- (quote (:optional-on :optional-off :components))) type) (while --dolist-tail-- (setq type (car --dolist-tail--)) (let ((--dolist-tail-- (plist-get based-on type)) comp) (while --dolist-tail-- (setq comp (car --dolist-tail--)) (if (memq comp included) nil (setq curr-plist ...)) (setq --dolist-tail-- (cdr --dolist-tail--)))) (setq --dolist-tail-- (cdr --dolist-tail--)))) (if (and (not (plist-get curr-plist :options-menu)) (plist-get based-on :options-menu)) (progn (setq curr-plist (plist-put curr-plist :options-menu (plist-get based-on :options-menu))))) (puthash "lvl5" curr-plist ergoemacs-theme-hash)) (if nil (puthash "silent-themes" silent ergoemacs-theme-hash) (puthash "defined-themes" themes ergoemacs-theme-hash)) (let ((plist (quote (:name "lvl5-theme" :description "Generated theme component for lvl5 theme"))) (fun (quote (lambda nil (ergoemacs-component-struct--define-key (quote global-map) (kbd "C-c <ergoemacs-timeout>") (quote ergoemacs-copy-line-or-region)) (ergoemacs-component-struct--define-key (quote global-map) (kbd "<C-insert>") (quote ergoemacs-copy-line-or-region)) (ergoemacs-component-struct--define-key (quote global-map) (kbd "C-S-v") (quote ergoemacs-paste-cycle)) (ergoemacs-component-struct--define-key (quote global-map) (kbd "<S-insert>") (quote ergoemacs-paste)) (ergoemacs-component-struct--define-key (quote global-map) (kbd "C-v") (quote ergoemacs-paste)))))) (if (boundp (quote ergoemacs-component-hash)) nil (defvar ergoemacs-component-hash (make-hash-table :test (quote equal)) "Hash of ergoemacs theme components")) (defvar ergoemacs-mode-reset) (setq ergoemacs-mode-reset t) (puthash "lvl5-theme" (list (quote lambda) nil (plist-get plist :description) (list (quote ergoemacs-component-struct--create-component) (list (quote quote) plist) (list (quote quote) fun) (or load-file-name buffer-file-name))) ergoemacs-component-hash) nil))
  (ergoemacs-theme lvl5 nil "CUA-mode style" (global-set-key (kbd "C-c <ergoemacs-timeout>") (quote ergoemacs-copy-line-or-region)) (global-set-key (kbd "<C-insert>") (quote ergoemacs-copy-line-or-region)) (global-set-key (kbd "C-S-v") (quote ergoemacs-paste-cycle)) (global-set-key (kbd "<S-insert>") (quote ergoemacs-paste)) (global-set-key (kbd "C-v") (quote ergoemacs-paste)))
  packages-init-hook()
  run-hooks(after-init-hook)
  command-line()
  normal-top-level()
mattfidler commented 8 years ago

This is because you initialize a theme in a package-init-hook that is run after loadup. Therefore, when ergoemacs-mode attempts to remember where the theme is created, it fails. (When running the hook, the load file is nil).

mattfidler commented 8 years ago

I would suggest that you separate out any themes in a separate file and then load the theme as follows:

(if ergoemacs-mode--fast-p
    (provide 'ergoemacs-themes)
    (load "ergoemacs-themes"))

When caching is enabled, the theme file is recalled, and not saved, reducing loadup time.

mattfidler commented 8 years ago

It also alleviates this issue.

However, using your theme, I can now startup, but cannot describe the theme. It has a max-lisp-eval-depth similar to #385.

mattfidler commented 8 years ago

Did the error stop for you?

samis commented 8 years ago

I succeeded in creating a custom ergoemacs theme. The code is freely available from my dotfiles repository.

mattfidler commented 8 years ago

The theme was:

(ergoemacs-theme CUA ()
  "My custom Ergoemacs theme mostly based around the basic CUA/Windows shortcuts"
  :components '(move-bracket standard-fixed ergoemacs-remaps standard-vars)
  ; For menu bars, the order is reversed.
  :optional-on '(tab-indents-region fixed-bold-italic menu-bar-help menu-bar-languages menu-bar-view menu-bar-search
         menu-bar-edit menu-bar-file))

Was it easy to figure out?

samis commented 8 years ago

I started the theme by copying and modifying the standard ergoemacs theme and then proceeded to modify and tweak it to fit my desires.

mattfidler commented 8 years ago

Thanks for the feedback!