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

hooks added to prog-mode-hook in user-config is not run when filename is passed as an emacs argument #4741

Closed
letheed opened this issue Jan 22, 2016 · 11 comments
Labels

Comments

@letheed
Copy link

letheed commented Jan 22, 2016

I've added the following code in dotspacemacs/user-config:

(add-hook 'prog-mode-hook 'highlight-indentation-mode)
(add-hook 'prog-mode-hook 'fci-mode)

However, the modes aren't toggled on neither in Rust mode nor in Haskell mode anymore since 0.104 -> 0.105 I think. IFAIK that was the correct way to do it. The hooks run properly when I open the spacemacs dotfile though.
I've moved the code to dotspacemacs/user-init which I'm not sure is correct, but does the trick for now. However I'm getting the following error in the *Messages* buffer:

File mode specification error: (void-function fci-mode)
@bmag
Copy link
Collaborator

bmag commented Jan 22, 2016

The void-function error indicates that some prog-mode buffer is opened after user-init and before fci-mode is available. I'd guess it's the scratch buffer. But IMO the real problem is that putting those lines in user-config should work, so lets focus on that.

I don't have haskell or rust layers enabled, but putting those lines in user-config should work. Please check:

  • if you open files of other programming languages (e.g. elisp), do they have fci-mode/auto-indentation-mode toggled on?
  • is it possible that some Rust/Haskell files are opened automatically before their layers are loaded? Do you use some auto-restoration feature (e.g. desktop-mode, layouts auto-restore)?
  • the buffers that don't have fci-mode/highlight-indentation-mode toggled, are they really in haskell-mode/rust-mode? (SPC h d v major-mode will tell you)
  • what are the values of prog-mode-hook, haskell-mode-hook and rust-mode-hook?
  • do haskell-mode and rust-mode really derive from prog-mode? use SPC h d f haskell-mode, then follow the link to the source code and you should see if it derives or not (same for rust-mode, of course).
  • what happens if you run the command M-x haskell-mode from a Haskell buffer?

Also, you might want to paste here the system information provided by SPC h d s.

@StreakyCobra
Copy link
Contributor

@letheed I haven't checked why your code is not working, but in my user-config I have this:

  ;; Activate column indicator in prog-mode and text-mode, except for org-mode
  (add-hook 'prog-mode-hook 'turn-on-fci-mode)
  (add-hook 'text-mode-hook 'turn-on-fci-mode)
  (add-hook 'org-mode-hook 'turn-off-fci-mode 'append)

And it's working.

@letheed
Copy link
Author

letheed commented Jan 22, 2016

@bmag

  • aside from the spacemacs dotfile, the modes are never turned on, I tried *.py and *.el files, aside from rust and haskell.
  • no, I don't use any module of the sort. I've included a diff of my .spacemacs for reference.
  • the buffers are in rust-mode and haskell-mode as expected
  • I've checked the hooks before, the hooks seemed all right:

prog-mode-hook:

(fci-mode highlight-indentation-mode spacemacs/load-yasnippet spacemacs//show-trailing-whitespace smartparens-mode rainbow-delimiters-mode spacemacs//enable-hs-minor-mode hl-todo-mode highlight-parentheses-mode highlight-numbers-mode clean-aindent-mode auto-highlight-symbol-mode linum-mode bug-reference-prog-mode goto-address-prog-mode)

haskell-mode-hook:

(spacemacs/init-haskell-mode ghc-init flycheck-mode spacemacs//init-company-haskell-mode company-mode)

rust-mode-hook:

(eldoc-mode racer-mode flycheck-mode spacemacs//init-company-rust-mode company-mode)
  • yes, they do derive from prog-mode. Both contain the following:
(defalias 'rust-parent-mode
  (if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode))
  • if I run haskell-mode or rust-mode, then fci-mode and highlight-indentation-mode are turned on, which shows something went wrong the first time.

System Info

  • OS: gnu/linux
  • Emacs: 24.5.1
  • Spacemacs: 0.105.9
  • Spacemacs branch: master (rev. 0562f05)
  • Distribution: spacemacs
  • Editing style: hybrid
  • Completion: helm
  • Layers:
((auto-completion :variables auto-completion-enable-sort-by-usage t)
 bepo better-defaults
 (c-c++ :variables c-c++-enable-clang-support t)
 colors emacs-lisp git github
 (haskell :variables haskell-enable-ghci-ng-support t)
 markdown
 (org :variables org-enable-github-support t)
 shell shell-scripts syntax-checking
 (rust :variables rust-enable-racer t)
 yaml)

@StreakyCobra I've tried replacing fci-mode with turn-on-fci-mode and highlight-indentation-mode with toggle-highlight-indentation-on in my user-config but it did not work any better. Actually both modes did not even turn on in the spacemacs dotfile edition buffer anymore, which is the only one where it works automatically right now.

I should add that I tried deleting the .emacs folder and recloning the spacemacs git rep' to reinstall everything from scratch, keeping only the dotfile.

@letheed
Copy link
Author

letheed commented Jan 26, 2016

I just had an idea and tried it: it turns out that the problem happens when I open a file by passing it's name as an argument to emacs as in emacs src/main.rs. If I open emacs first and then SPC f f open the file from there the hooks run properly. I'm sorry I didn't find that out earlier, I just don't do that very often.

@letheed letheed changed the title hook added to prog-mode-hook does not run vs void-function hooks added to prog-mode-hook in user-config is not run when filename is passed as an emacs argument Jan 26, 2016
@StreakyCobra
Copy link
Contributor

@letheed If you want to use emacs in this way (i.e. calling emacs <filename>) then you may consider using the daemon mode with emacsclient, it offers the behaviour you want :-) and in a much more efficient way ;-)

@letheed
Copy link
Author

letheed commented Jan 26, 2016

@StreakyCobra Yeah, I understand that. To be honest, I've had an emacs server running as a systemd user service for months and I never use it. Old habits die hard I figure.
But it's not just that, I've often found the emacs server way to be less reliable in subtle ways. For example since it's not actually part of my user session it doesn't inherit my custom path, which means I must re-add it manually in .spacemacs to the exec-path variable. Same goes for other environmental variable like RUST_SRC_PATH. Now if I open a normal emacs session, it will set them up twice. And there's the duplication, if I modify my path or env somewhere I have to not forget and do it twice. It's dirty.
I found that contradictory with the attitude that things should just work, which is the reason for Spacemacs in the first place.
But I'll give it a try, since it solves my pb for now :)
I still consider the current behaviour to be a bug though. It's also a regression since it used to work properly. Clearly emacs opens the file before the user-config is executed.
And BTW thanks for your bepo layer. I bravely tried learning the vim way when I moved to spacemacs but the hjkl thing was so painful I just went hybrid, and almost never leave the insertion mode >_>
Maybe I'll stick to it the next time I can muster the courage to try and learn it...

@StreakyCobra
Copy link
Contributor

an emacs server running as a systemd user service

It's exactly what I have right now :-)

It doesn't inherit my custom path […] Same goes for other environmental variable

Add this code to your user-config. It will use the exec-path-from-shell package to get the PATH, MANPATH and the environment variables you will list there, from your zsh or bash rc-files.

(setq exec-path-from-shell-variables
      (append exec-path-from-shell-variables
              (list "TERM"
                    "RUST_SRC_PATH"
                    ""
                    )))
(exec-path-from-shell-initialize)

And BTW thanks for your bepo layer.

My pleasure. It's closer to a hack than a real feature, but it's still better than nothing ;-)

@letheed
Copy link
Author

letheed commented Jan 26, 2016

Ha ha you sir are a wizard...
Thank you very much, that did the trick :)

@StreakyCobra
Copy link
Contributor

👍

@d12frosted
Copy link
Collaborator

Closing this issue as the problem was resolved.

@guraltsev
Copy link

This doesn't solve the original problem! Please reopen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants