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

Add #'projectile-track-known-projects-find-file-hook to 'buffer-list-update-hook #1895

Merged
merged 1 commit into from
Aug 24, 2024

Conversation

jtamagnan
Copy link
Contributor

@jtamagnan jtamagnan commented Jun 21, 2024

Foreword

I originally created #1879 but have since deleted that GitHub account,
as such the associated repository and pull request were closed. The
new version of that PR can be found at #1894.

This PR implements Solution 2 as described in #1894.

Problem

There are certain modes for which the
projectile-find-file-hook-function function does not run by
default. This includes, shell, eshell, and magit. If one
navigates directly to one of these buffers and calls
projectile-relevant-known-projects while
projectile-current-project-on-switch is set to 'keep they will
notice that the first repository in the list is not the one that they
expect

Solution

There are two possible solutions that come immediately to mind. I
want to mention both of them for consideration though naturally
this PR only implements one of them:

  1. Add a new 'front option for
    projectile-current-project-on-switch such that the first item is
    the project associated with the current buffer.
  2. Modify projectile-mode to add the hook to
    buffer-list-update-hook such that the current buffer is always
    added to the list of known-projects.

This PR implements Solution 2.
#1894 implements Solution 1.

Comparision

The main drawback with Solution 1 is that the newly selected project
will not be added to the projects list.

The main drawback of Solutionk 2 is that it will not work on versions
of emacs earlier than 28.1 because buffer-list-update-hook works
differently.


Before submitting a PR make sure the following things have been done (and denote this
by checking the relevant checkboxes):

  • The commits are consistent with our contribution guidelines
  • You've added tests (if possible) to cover your change(s)
  • All tests are passing (eldev test)
  • The new code is not generating bytecode or M-x checkdoc warnings
  • You've updated the changelog (if adding/changing user-visible functionality)
  • You've updated the readme (if adding/changing user-visible functionality)

Thanks!

@jtamagnan jtamagnan changed the title Add #'projectile-track-knonw-projects-find-file-hook to 'buffer-list-update-hook Add #'projectile-track-known-projects-find-file-hook to 'buffer-list-update-hook Jun 21, 2024
@jtamagnan jtamagnan force-pushed the buffer-list-update-hook-approach branch from 1c42b25 to 93f3b14 Compare June 21, 2024 21:22
@jtamagnan jtamagnan force-pushed the buffer-list-update-hook-approach branch 3 times, most recently from c16d5c9 to 451e648 Compare June 28, 2024 18:43
@jtamagnan jtamagnan force-pushed the buffer-list-update-hook-approach branch from 451e648 to f0bedae Compare June 28, 2024 22:46
projectile.el Show resolved Hide resolved
@bbatsov
Copy link
Owner

bbatsov commented Aug 14, 2024

This solution is preferable to me, so let's go with it. I find it to be cleaner, and most Emacs users are likely using Emacs 28+ anyways.

@jtamagnan jtamagnan force-pushed the buffer-list-update-hook-approach branch from f0bedae to a2364ea Compare August 14, 2024 22:37
@jtamagnan
Copy link
Contributor Author

jtamagnan commented Aug 14, 2024

Thank you for the review


This solution is preferable to me, so let's go with it. I find it to be cleaner, and most Emacs users are likely using Emacs 28+ anyways.

Agreed, this one seems more robust. I've closed out the other pull-request.


I've pulled from upstream, added a code comment, and pushed the new commit. Hopefully it is in a better state now

@bbatsov bbatsov merged commit 3c92d28 into bbatsov:master Aug 24, 2024
7 checks passed
@bbatsov
Copy link
Owner

bbatsov commented Aug 24, 2024

Thanks!

@jtamagnan
Copy link
Contributor Author

@bbatsov thank you for the package, the conversation, and the reviews

topalovic added a commit to topalovic/.emacs.d that referenced this pull request Aug 29, 2024
It slows down tabbing through org table cells to a crawl:

887  98% - command-execute
887  98%  - call-interactively
887  98%   - funcall-interactively
676  75%    - org-cycle
675  75%     - call-interactively
675  75%      - funcall-interactively
675  75%       - org-table-next-field
675  75%        - org-table-align
348  38%         - org-string-width
347  38%          - set-window-buffer
347  38%           - record-window-buffer
347  38%            - run-hooks
347  38%             - projectile-track-known-projects-find-file-hook

The change was introduced in bbatsov/projectile#1895
@dgutov
Copy link
Contributor

dgutov commented Sep 8, 2024

Hi!

FWIW, this might be suboptimal because the "temporary" buffers that Emacs 28+ treats specially are just the ones that had been created with non-nil second (new and optional) argument to get-buffer-create.

Which probably means that the contents of this hook will still run in many cases of buffers created for "temporary" work. See company-mode/company-mode#1492 or the Org related commit above referencing this issue.

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

Successfully merging this pull request may close these issues.

3 participants