Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't open more than one emacs frame (Invalid face: linum). #6104

Closed
Stebalien opened this issue May 20, 2016 · 12 comments
Closed

Can't open more than one emacs frame (Invalid face: linum). #6104

Stebalien opened this issue May 20, 2016 · 12 comments
Labels
- Bug tracker - Running as daemon stale marked as a stale issue/pr (usually by a bot) To be reproduced

Comments

@Stebalien
Copy link
Contributor

Description

Since fa4eeb4, I can't open more than one emacs frame (client/daemon).

Reproduction guide

  • Start Emacs as a daemon.
  • Open an emacs frame (emacsclient -c -n).
  • Repeat once.

Observed behaviour:

emacsclient spits out the following when run the second time:

*ERROR*: Invalid face: linum

There are no relevant errors in the *messages* buffer (as far as I can tell).

Expected behaviour:

Two frames are opened.

System Info

  • OS: gnu/linux
  • Emacs: 24.5.1
  • Spacemacs: 0.105.20
  • Spacemacs branch: develop (rev. da55a89)
  • Graphic display: t
  • Distribution: spacemacs
  • Editing style: vim
  • Completion: helm
  • Layers:
(helm better-defaults git
      (auto-completion :variables auto-completion-return-key-behavior nil)
      org spell-checking syntax-checking
      (shell :variables shell-default-shell 'ansi-term)
      emoji emacs-lisp markdown latex yaml c-c   html haskell go javascript python systemd
      (rust :variables rust-format-on-save nil))
@Stebalien
Copy link
Contributor Author

Stebalien commented May 20, 2016

It appears that this bug disappears when either the *Messages* or *spacemacs* buffer is open in some frame (this doesn't apply to the *scratch* buffer).

@Stebalien
Copy link
Contributor Author

Disabling the dotspacemacs-line-numbers setting works around the bug.

@Stebalien
Copy link
Contributor Author

It appears that this bug disappears when either the Messages or spacemacs buffer is open in some frame (this doesn't apply to the scratch buffer).

I believe this is because I don't have line numbers enabled in these modes.

@lukepfister
Copy link

I'm pretty sure this is related to this issue: kaushalmodi/.emacs.d#4

I haven't tried the proposed fix.

@Stebalien
Copy link
Contributor Author

It looks related. Unfortunately, that fix only seems to allow one frame to load. Really, it looks like nlinum--setup-window (nlinum.el) needs to be modified to not run until after the frame is loaded. Is there any way to tell if the current frame is completely loaded? I was able to get it to work by adding:

(defvar frame-ready nil)
(add-hook 'after-make-frame-functions (lambda (frame) (set-frame-parameter frame 'frame-ready t)))
(add-hook 'after-init-hook (lambda () (set-frame-parameter nil 'frame-ready t)))

To mark a frame as "ready" and changing:

(defun nlinum--setup-window ()
  (let ((width (if (display-graphic-p)
                   (ceiling
                    (let ((width (nlinum--face-width 'linum)))
                      (if width
                          (/ (* nlinum--width 1.0 width)
                             (frame-char-width))
                        (/ (* nlinum--width 1.0
                              (nlinum--face-height 'linum))
                           (frame-char-height)))))
                 nlinum--width)))
    (set-window-margins nil (if nlinum-mode width)
                        (cdr (window-margins)))))

To:

(defun nlinum--setup-window ()
  (let ((width (if (and frame-ready (display-graphic-p)) ;; <-- Here
                   (ceiling
                    (let ((width (nlinum--face-width 'linum)))
                      (if width
                          (/ (* nlinum--width 1.0 width)
                             (frame-char-width))
                        (/ (* nlinum--width 1.0
                              (nlinum--face-height 'linum))
                           (frame-char-height)))))
                 nlinum--width)))
    (set-window-margins nil (if nlinum-mode width)
                        (cdr (window-margins)))))

@Stebalien
Copy link
Contributor Author

There appears to be a two year old upstream report: https://lists.gnu.org/archive/html/bug-gnu-emacs/2014-10/msg00126.html

@StreakyCobra
Copy link
Contributor

@Stebalien FYI fd756a1 reverted line numbers back to the linum package.

@Stebalien
Copy link
Contributor Author

@StreakyCobra Thanks! (Although it might be a good idea to keep this open as there is still an nlinum layer which may eventually, from what I've read, be enabled by default).

toupeira added a commit to toupeira/dotfiles that referenced this issue May 30, 2016
@zw963
Copy link

zw963 commented Jun 25, 2016

Following code is worked for only one frame.

(defun initialize-nlinum (&optional frame)
  (require 'nlinum)
  (add-hook 'prog-mode-hook 'nlinum-mode))
(when (daemonp) (add-hook 'window-setup-hook 'initialize-nlinum))

But, I still not find out a way to make make-frame worke well with nlinum-mode.

@zw963
Copy link

zw963 commented Jun 25, 2016

Because I use make-frame to create new frame, following snippets worked for me at least for now.

(defun initialize-nlinum (&optional frame)
  (require 'nlinum)
  (add-hook 'prog-mode-hook 'nlinum-mode))
(when (daemonp)
  (add-hook 'window-setup-hook 'initialize-nlinum)
  (defadvice make-frame (around toggle-nlinum-mode compile activate)
  (nlinum-mode -1) ad-do-it (nlinum-mode 1)))

Those code make my emacs 24.5.1 daemon mode worked with nlinum-mode very well.
no matter what open a frame from terminal or create a new frame in emacs.

@kaushalmodi
Copy link
Contributor

kaushalmodi commented Jun 28, 2016

Simply running linum/nlinum in after-make-frame-functions hook works when (daemonp).
Below modi/toggle-linum is simply my wrapper to enable/disable linum/nlinum.

;; Set/unset linum
(if (daemonp)
    ;; Need to delay linum activation till the frame and fonts are loaded, only
    ;; for emacsclient launches. For non-daemon, regular emacs launches, the
    ;; frame is loaded *before* the emacs config is read. Not doing so results
    ;; in the below error in emacs 24.5:
    ;;   *ERROR*: Invalid face: linum
    (add-hook 'after-make-frame-functions #'modi/toggle-linum)
  ;; Even when running in non-daemon mode, run `modi/toggle-linum' only after the
  ;; init has loaded, so that the last modified value of `modi/linum-fn-default'
  ;; if any in setup-personal.el is the one effective, not its standard value
  ;; in its defvar form above.
  (add-hook 'after-init-hook #'modi/toggle-linum))

https://github.com/kaushalmodi/.emacs.d/blob/c5a7d1a9c0aba5c80fac7be87ece0afffc51099b/setup-files/setup-linum.el#L166-L178

PS: I was surprised to see my config referenced here :)

seagle0128 added a commit to seagle0128/.emacs.d that referenced this issue Aug 3, 2017
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- Bug tracker - Running as daemon stale marked as a stale issue/pr (usually by a bot) To be reproduced
Projects
None yet
Development

No branches or pull requests

5 participants