Bad-ptr / persp-mode.el

named perspectives(set of buffers/window configs) for emacs
400 stars 44 forks source link

Why does persp-keymap-prefix needs to be set before activating the mode? #63

Open angrybacon opened 7 years ago

angrybacon commented 7 years ago

I'm trying to have require-final-newline set to nil only when saving configuration files only.

(setq-default
 require-final-newline 'visit
 use-package-always-defer t)

(use-package persp-mode
  :defer 1
  :init (setq-default persp-keymap-prefix (kbd "C-c w"))
  :config
  (persp-mode 1)
  (add-to-list 'persp-before-save-state-to-file-functions
               (lambda (file persps persp-file)
                 (setq-local require-final-newline nil)))
  (setq-default
   persp-auto-resume-time 0.1
   persp-auto-save-num-of-backups 1
   persp-autokill-buffer-on-remove 'kill-weak
   persp-save-dir (expand-file-name ".persp-confs/" user-emacs-directory)))

With the above it still asks me to confirm whether I want to add a newline at the end of the file.

Another thing, I don't understand the necessity for the keymap prefix to be set in the :init clause.

angrybacon commented 7 years ago

Looks like using mode-require-final-newline instead did the trick.

Leaving this open for my second issue, that is: why do I need to set persp-keymap-prefix before activating the mode?

Bad-ptr commented 7 years ago

why do I need to set persp-keymap-prefix before activating the mode?

And what is wrong with that? I guess you need to set it before activating the mode because the defcustom declaration of the persp-keymap-prefix has the :set function, so actually it will bind the prefix during evaluation of the source code of the persp-mode.el, even if the persp-mode is not activated.

Bad-ptr commented 7 years ago

And about your first issue:

Looks like using mode-require-final-newline instead did the trick.

Actually I don't see how this may help you. ) (setq-local require-final-newline nil) in the persp-before-save-state-to-file-functions is useless, because it will set for your current buffer and not for the temp buffer that the persp-mode creates to save it's state.

As I understand your issue here is that it asks you whether you what to add newline or not every time the persp-mode saves it's state, right? Then I can set the require-final-newline to t during saving the perspectves state, will it be OK for you?

angrybacon commented 7 years ago

And what is wrong with that?

Nothing wrong I guess, I naively thought THE way to do it was to first activate a mode and then alter its settings.

As I understand your issue here is that it asks you whether you what to add newline or not every time the persp-mode saves it's state, right?

Basically, I want the behavior of require-final-newline set to 'visit. Except many major modes actually use the value of mode-require-final-newline instead (default to t). Long story short, I've been living with require-final-newline set to t (which does not ask). My guess is that your package was one of the few to actually use 'visit amongst those I use (which will ask) since it was using require-final-newline's value directly (that I had set to 'visit).

But yes you're right, the lambda is now useless since I directly set mode-require-final-newline to 'visit. That way your package will use the unaltered value of require-final-newline (t or nil i can't remember) which will not ask.

I could be wrong though, I'm traveling and cannot check right now.