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

[BUG?] persp-add-buffer-on-after-change-major-mode does not support function choice #147

Open
sfavazza opened this issue Nov 11, 2023 · 2 comments

Comments

@sfavazza
Copy link

Hello,

I wanted to create a function to add files to a perspective, only if belonging to a project or a list of projects. I thought that the best way to introduce this custom feature would have been persp-add-buffer-on-after-change-major-mode, as according to its documentation it would support a custom function.

Though in the implementation it does not look like it.

Is this intended? Am I missing something?

As a workaround I am currently implementing my functionality as a persp-add-buffer-on-after-change-major-mode-filter-functions function.

@miguebox
Copy link

I am facing this same issue @sfavazza .

As a workaround, instead of using persp-add-buffer-on-after-change-major-mode-filter-functions, which exlcudes buffers

Additional filters to know which buffers we dont want to add to
the current perspective after the after-change-major-mode-hook is fired.

you can implement a hook similar to persp-after-change-major-mode-h, which is what persp-add-buffer-on-after-change-major-mode enables when set.

This is what I use:

(defcustom migue/persp-major-mode-change-functions nil
  "List of functions to run when changing major-modes. If they return true, add the buffer to the current
perspective."
  :group 'persp-mode
  :type 'hook
  )
(defun migue/persp-major-mode-check ()
  "Check functions in `migue/persp-major-mode-change-functions', if they return true, add them to the
current perspective."
  (let ((buf (current-buffer)))
    (when (cl-find-if (lambda (filter)
                        (if (functionp filter)
                            (funcall filter buf)
                          ))
                      migue/persp-major-mode-change-functions)
      (persp-add-buffer buf (get-current-persp) nil nil)
      )
    )
  )
(add-hook 'after-change-major-mode-hook #'migue/persp-major-mode-check)

It's all basically a stripped down version of persp-after-change-major-mode-h, like I said, and persp-buffer-filtered-out-p; but it allows you to choose what types of buffers you want on a case-by-case basis.

For instance, to add dired buffers:

(with-eval-after-load 'persp-mode
  (add-hook 'migue/persp-major-mode-change-functions
            #'(lambda (buffer) (equal (with-current-buffer buffer major-mode) 'dired-mode)))
  )

I don't think this would be too hard to implement, but my way is probably lacking in some way, which is why I haven't refined it and made a pull request 😅.

@Bad-ptr
Copy link
Owner

Bad-ptr commented Jul 26, 2024

must be fixed 84bc787

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

No branches or pull requests

3 participants