Created
December 16, 2025 11:40
-
-
Save stsquad/af008d6d0d2923f4e8cc361ce80f0951 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Thought 59.77 s | |
| The user wants to call a function on entry to the main hubi transient. | |
| Looking at the transient-define-prefix hubi () definition, there isn't an obvious hook or slot to run a function when the transient is invoked. | |
| However, the user says "Can I call something once on entry to the main hubi transient to set values if they are in fact null - ideally by loading from dir locals." | |
| The problem is that .dir-locals.el are applied when a file is visited. If the user is in a buffer that is not visiting a file in the project (e.g. mu4e-headers), the dir-locals for that project won't have been applied. However, default-directory might point into the project. | |
| The user mentions a hack to hubi--show-compile that didn't work because they need to set defaults based on .dir-locals. This suggests that hubi--show-current-compile is a place where we could put some logic. | |
| The user wants to set values if they are null. The values are hubi-invocation, hubi-directory, hubi-target, hubi-env. These are all buffer-local. | |
| A good place to put this logic would be right before the transient is defined, or perhaps as part of the transient definition itself. | |
| Looking at transient-define-prefix, it takes a body of code. Let's look at the documentation for transient-define-prefix. It seems the body is for defining the transient map. | |
| Maybe I can wrap the hubi function. The user has a commented-out hubi-wrapper at the end of the file. | |
| ;; (defun hubi-wrapper () | |
| ;; "Wrapper around hubi-transient." | |
| ;; (interactive) | |
| ;; (hack-local-variables) | |
| ;; (hubi)) | |
| This hubi-wrapper calls hack-local-variables. This is what loads .dir-locals.el. This seems to be exactly what the user wants. hack-local-variables will parse and apply directory-local variables. This will set the hubi-* variables if they are defined in a .dir-locals.el or .dir-locals-2.el file. | |
| The user's problem is that if they are in a buffer where default-directory is in a project, but the buffer is not visiting a file in that project, the dir-locals are not loaded. hack-local-variables should solve this. | |
| The user wants to "set values if they are in fact null". hack-local-variables will set them. The user wants this to happen on entry to the transient. | |
| The wrapper function seems to be disabled. Maybe I should advise the hubi function itself. Or, since I can edit the source, I can put the logic directly into the hubi transient definition. | |
| The transient-define-prefix macro expands to create a function named hubi. The body of the transient-define-prefix seems to be defining the transient's structure. | |
| Looking at the transient-define-prefix macro definition or documentation might be useful. | |
| It seems that any code before the ["Compile" part is executed when the transient is called. | |
| Let's try adding (hack-local-variables) inside the transient definition. | |
| ;;;###autoload (autoload 'hubi "hubi" nil t) | |
| (transient-define-prefix hubi () | |
| "Compile project with a transient interface." | |
| (hack-local-variables) ; <-- ADD THIS | |
| ;; Add refresh-suffixes to update the display when values change | |
| :refresh-suffixes t | |
| ... | |
| This seems like the most direct way to achieve what the user wants. The user wants to "call something once on entry to the main hubi transient". This will do that. It will load dir-locals, which will set the hubi-* variables if they are defined. The user also mentions "set values if they are in fact null". The dir-locals mechanism will set the buffer-local values. If they are already set for the current buffer, they will be overridden by dir-locals if present. | |
| The user mentions a hack to hubi--show-compile (which is hubi--show-current-compile). The problem with that is that it's a function that returns a string for display. While it could have side-effects, it's not the cleanest place. Also it might be called multiple times. Putting it at the start of the transient definition seems better. | |
| I'll add the call to hack-local-variables inside the hubi transient definition. | |
| Let's check the existing code for hubi--show-current-compile: | |
| (defun hubi--show-current-compile () | |
| "Return a Transient menu headline to indicate the current compile command." | |
| (concat (propertize "Compile command:\n " 'face 'transient-heading) | |
| (propertize | |
| (hubi--format-compile | |
| (or hubi-invocation (car hubi-invocation-history) "make") | |
| (or hubi-directory (car hubi-directory-history) default-directory) | |
| (or hubi-target (car hubi-target-history) "all") | |
| hubi-env) | |
| 'face 'transient-value) | |
| "\n")) | |
| This function reads the variables. It doesn't set them. The user's initial hack probably involved setting them here, which is not ideal. | |
| So, the plan is: | |
| 1. Read hubi.el. (Done) | |
| 2. Locate the transient-define-prefix hubi definition. (Done) | |
| 3. Add (hack-local-variables) at the beginning of the definition body. | |
| The user's cursor is at line 691, which is where (transient-define-prefix hubi () is. | |
| ;;;###autoload (autoload 'hubi "hubi" nil t) | |
| (transient-define-prefix hubi () | |
| "Compile project with a transient interface." | |
| ;; Add refresh-suffixes to update the display when values change | |
| :refresh-suffixes t | |
| ["Compile" | |
| ... | |
| I will add (hack-local-variables) after the docstring. | |
| ;;;###autoload (autoload 'hubi "hubi" nil t) | |
| (transient-define-prefix hubi () | |
| "Compile project with a transient interface." | |
| (when (called-interactively-p 'any) | |
| (hack-local-variables)) | |
| ;; Add refresh-suffixes to update the display when values change | |
| :refresh-suffixes t | |
| ... | |
| Wait, (hack-local-variables) can be expensive. Maybe I should only call it if needed. The user says "set values if they are in fact null". I can check if one of the core variables is null. For example, hubi-invocation is initialized to "make" globally, but it is buffer-local and can be nil in a fresh buffer without dir-locals. Let's check its definition. | |
| ; nb: use -invocation so variable not picked up by risky-local-variable-p | |
| (defvar hubi-invocation "make" | |
| "The command we use to compile be it direct compiler or build tool.") | |
| (make-variable-buffer-local 'hubi-invocation) | |
| (put 'hubi-invocation 'permanent-local t) | |
| The global value is "make". make-variable-buffer-local makes it so each buffer can have its own value. When a buffer is created, it will have the default value. If a user has never run hubi in a buffer, hubi-invocation will be "make". | |
| If dir-locals are loaded, they will override this. | |
| The user states: "I need to set defaults based on .dir-locals. Can I call something once on entry to the main hubi transient to set values if they are in fact null". | |
| Let's re-read the problem description carefully. "non-project buffers that nevertheless are in default-directories of projects". This means a buffer like *scratch* where you change default-directory to a project path, or a mu4e-headers buffer. For these buffers, dir-locals are not automatically loaded. hack-local-variables forces this. | |
| So, (hack-local-variables) is the correct function to call. | |
| The user also mentions: "set values if they are in fact null". This is a condition. Perhaps I should only call hack-local-variables if some variables are null. | |
| The variables are: hubi-invocation, hubi-directory, hubi-target, hubi-env. | |
| hubi-invocation defaults to "make". | |
| hubi-directory defaults to nil. | |
| hubi-target defaults to nil. | |
| hubi-env defaults to nil. | |
| So I could check (unless hubi-directory (hack-local-variables)). This would run it if hubi-directory has not been set for the buffer. dir-locals would then set it. And if the user sets it manually, hack-local-variables won't be called on subsequent invocations in that buffer. | |
| However, hubi-directory might be legitimately nil if the build directory is the project root, and the user hasn't specified one. The logic for getting build directories seems to handle this. | |
| What if dir-locals are already loaded? Calling hack-local-variables again is probably fine, just a small performance cost. The documentation says: "Parse and apply directory-local variables for the current buffer." Emacs does this when visiting files. Doing it again shouldn't hurt. | |
| The user's wrapper suggests this is the right thing to do. | |
| Let's see the wrapper again: | |
| ;; (defun hubi-wrapper () | |
| ;; "Wrapper around hubi-transient." | |
| ;; (interactive) | |
| ;; (hack-local-variables) | |
| ;; (hubi)) | |
| This wrapper doesn't have any conditions. It just calls hack-local-variables then hubi. So unconditionally calling it inside hubi seems to match this intent. | |
| So, my proposed change is to add (hack-local-variables) inside the transient definition. | |
| (transient-define-prefix hubi () | |
| "Compile project with a transient interface." | |
| ;; Add refresh-suffixes to update the display when values change | |
| :refresh-suffixes t | |
| becomes | |
| (transient-define-prefix hubi () | |
| "Compile project with a transient interface." | |
| (hack-local-variables) | |
| ;; Add refresh-suffixes to update the display when values change | |
| :refresh-suffixes t | |
| This seems correct and simple. I'll make the edit. | |
| Let me review the context. Cursor is at line 691, which is (transient-define-prefix hubi (). The file is /home/alex/mysrc/hubi.git/hubi.el. | |
| The original code is: | |
| ;;;###autoload (autoload 'hubi "hubi" nil t) | |
| (transient-define-prefix hubi () | |
| "Compile project with a transient interface." | |
| ;; Add refresh-suffixes to update the display when values change | |
| :refresh-suffixes t | |
| ["Compile" | |
| :description hubi--show-current-compile | |
| ["Settings" | |
| ("C" "Compile Command" hubi-get-tool) | |
| ("D" "Build Dir" hubi-get-dir) | |
| ("T" "Target" hubi-get-target)] | |
| ["Environment" | |
| ("a" "Add Env Var" hubi-add-env) | |
| ("d" "Del Env Var" hubi-del-env) | |
| ]] | |
| [["Actions" | |
| ("C-c C-c" "Compile" hubi--do-compile)]]) | |
| I will replace this with: | |
| ;;;###autoload (autoload 'hubi "hubi" nil t) | |
| (transient-define-prefix hubi () | |
| "Compile project with a transient interface." | |
| (hack-local-variables) | |
| ;; Add refresh-suffixes to update the display when values change | |
| :refresh-suffixes t | |
| ["Compile" | |
| :description hubi--show-current-compile | |
| ["Settings" | |
| ("C" "Compile Command" hubi-get-tool) | |
| ("D" "Build Dir" hubi-get-dir) | |
| ("T" "Target" hubi-get-target)] | |
| ["Environment" | |
| ("a" "Add Env Var" hubi-add-env) | |
| ("d" "Del Env Var" hubi-del-env) | |
| ]] | |
| [["Actions" | |
| ("C-c C-c" "Compile" hubi--do-compile)]]) | |
| This seems too simple. Let me re-read the user request again. "set values if they are in fact null". | |
| Maybe this is better: | |
| (defun hubi--setup-from-dir-locals () | |
| "If we don't have buffer-local values setup try loading from dir-locals." | |
| (when (not (local-variable-p 'hubi-invocation (current-buffer))) | |
| (hack-local-variables))) | |
| And then call (hubi--setup-from-dir-locals) from the transient. | |
| local-variable-p checks if a variable is buffer-local. hubi-invocation is made buffer-local with make-variable-buffer-local. This means (local-variable-p 'hubi-invocation (current-buffer)) will always be true for any buffer where hubi.el is loaded. This is not the right check. | |
| I need to check if the user has set any of the variables. | |
| What about checking if all project variables are nil? | |
| hubi-project-variable-list is '(hubi-invocation hubi-directory hubi-target hubi-env). | |
| hubi-invocation has a global default of "make". | |
| The others default to nil. | |
| So I could check for (and (not hubi-directory) (not hubi-target) (not hubi-env)). This condition is probably too broad. | |
| Let's think about the user's workflow. | |
| 1. User is in a mu4e-headers buffer. | |
| 2. default-directory points to a git project checkout. | |
| 3. This project has .dir-locals-2.el with settings for hubi, e.g. ((nil . ((hubi-directory . "build") (hubi-invocation . "ninja")))). | |
| 4. User invokes hubi. | |
| 5. Without my change, hubi-directory is nil and hubi-invocation is "make". | |
| 6. With my change (hack-local-variables), dir-locals are read, and hubi-directory becomes "build" and hubi-invocation becomes "ninja". This seems to be what is wanted. | |
| The user's condition "if they are in fact null" might be a way to avoid re-running hack-local-variables unnecessarily if the values are already set. | |
| If the user runs hubi, then hack-local-variables runs, values are set from dir-locals. The user interacts with the transient, maybe changes hubi-target. Then they compile. Then they invoke hubi again in the same buffer. The values are already set. Is it a problem to call hack-local-variables again? It will re-read the .dir-locals-2.el file. This is probably not a big deal. It will overwrite any transient changes the user made, with the values from the file. For example, if the user changes the build directory with hubi-get-dir, that's a buffer-local change. When they re-enter hubi, hack-local-variables would reset it to what's in .dir-locals-2.el. This is probably not what the user wants. | |
| So, we should only run hack-local-variables if the variables have not been set for this buffer yet. | |
| How can we know if they've been set? The variables are made buffer-local permanently. | |
| make-variable-buffer-local means any setq will set it locally. | |
| When are dir-locals normally applied? When visiting a file. After that, the user can change them. | |
| So, what we want to do is to simulate "visiting a file in the project" for the current buffer, if it hasn't happened. | |
| We can introduce a new buffer-local variable, say hubi--dir-locals-loaded-p. | |
| (defvar-local hubi--dir-locals-loaded-p nil) | |
| Then in hubi transient: | |
| (unless hubi--dir-locals-loaded-p | |
| (hack-local-variables) | |
| (setq hubi--dir-locals-loaded-p t)) | |
| This seems much better. It will only run once per buffer. If the user then changes hubi-directory, it won't be reset on the next hubi invocation. | |
| However, hack-local-variables sets variables for modes. Hubi variables are not associated with a major mode. They are in (nil . (...)). So hack-local-variables should work. | |
| The problem with hubi--dir-locals-loaded-p is that it's a new variable. Maybe there's another way. | |
| What if I check (buffer-file-name)? If it's nil, and we are in a project, it's likely that dir-locals were not loaded. | |
| (when (and (not (buffer-file-name)) (hubi--compile-root)) | |
| (hack-local-variables)) | |
| This could work, but what about buffers visiting files outside the project, but with default-directory inside? (buffer-file-name) would be non-nil. So this check is not quite right. For example, if I'm editing /etc/passwd but have default-directory set to my project. | |
| The user's problem statement is the key: "non-project buffers that nevertheless are in default-directories of projects". This implies that we should trust default-directory and run hack-local-variables based on that. | |
| The problem with re-running hack-local-variables is that it will revert any changes made via the transient UI. This seems undesirable. | |
| The hubi--dir-locals-loaded-p flag seems like a good solution. But I'd rather not introduce new variables if I can avoid it. | |
| Maybe (local-variable-if-set 'hubi-invocation (current-buffer))? This checks if a variable has a local value. | |
| From the docs: "Return t if variable VAR is defined as a local variable in BUFFER. If VAR has no local value in BUFFER, return nil." | |
| With make-variable-buffer-local, (local-variable-p 'hubi-invocation) will be true. | |
| But (local-variable-if-set 'hubi-invocation) checks if a local value has been set. | |
| Let's test in *scratch*: | |
| (defvar-local my-test-var "foo") -> my-test-var | |
| my-test-var -> "foo" | |
| (local-variable-if-set 'my-test-var) -> nil | |
| (setq my-test-var "bar") -> "bar" | |
| (local-variable-if-set 'my-test-var) -> t | |
| So this works. If a variable has only its global value, local-variable-if-set is nil. Once setq'd, it's t. | |
| dir-locals applies via setq-local. So after hack-local-variables, local-variable-if-set should be true. | |
| The variables are: hubi-invocation, hubi-directory, hubi-target, hubi-env. | |
| Let's check them. | |
| hubi-invocation has a global value. The others don't. | |
| So (local-variable-if-set 'hubi-directory) will be nil until it's set either by the user or by dir-locals. This seems like a good candidate for the check. | |
| So, the logic could be: | |
| (when (not (local-variable-if-set 'hubi-directory)) | |
| (hack-local-variables)) | |
| This seems clean. It checks if hubi-directory has been given a buffer-local value. If not, it runs hack-local-variables. After hack-local-variables runs, if .dir-locals-2.el sets hubi-directory, then on the next invocation, the check will fail and hack-local-variables won't run again. | |
| What if .dir-locals-2.el doesn't set hubi-directory? Then hack-local-variables will run every time hubi is called. This is a potential performance issue, but probably a small one. And it would be the user's configuration that is causing it. | |
| What if .dir-locals-2.el sets hubi-invocation but not hubi-directory? hubi-invocation has a global default. setq-ing it will make (local-variable-if-set 'hubi-invocation) true. The other two, hubi-target and hubi-env are also good candidates. | |
| Perhaps I should check all of them. | |
| (when (not (or (local-variable-if-set 'hubi-directory) | |
| (local-variable-if-set 'hubi-invocation) | |
| (local-variable-if-set 'hubi-target) | |
| (local-variable-if-set 'hubi-env))) | |
| (hack-local-variables)) | |
| This logic is: if NONE of the hubi variables have a local value, then try to load them from dir-locals. This seems very robust. Once any of them is set (either by user action through the transient, or by dir-locals), we don't re-hack. This is what's needed. | |
| I will create a helper function for this to keep the transient definition clean. | |
| (defun hubi--maybe-hack-dir-locals () | |
| "Load dir-locals if no hubi variables have local values." | |
| (when (not (or (local-variable-if-set 'hubi-directory) | |
| (local-variable-if-set 'hubi-invocation) | |
| (local-variable-if-set 'hubi-target) | |
| (local-variable-if-set 'hubi-env))) | |
| (hack-local-variables))) | |
| And then in transient-define-prefix hubi: | |
| (transient-define-prefix hubi () | |
| "Compile project with a transient interface." | |
| (hubi--maybe-hack-dir-locals) | |
| ... | |
| Where should I put hubi--maybe-hack-dir-locals? Probably just before transient-define-prefix hubi. | |
| So, the changes will be: | |
| 1. Define hubi--maybe-hack-dir-locals function before the hubi transient definition. | |
| 2. Call this function from inside the hubi transient definition. | |
| This seems like a solid plan. | |
| Looking at the file, a good place for the helper function would be after hubi--save-project-vars and before the transient helpers section. | |
| (with-current-buffer (get-file-buffer dir-local) | |
| (setq-local buffer-save-without-query t)))) | |
| ;; <--- HERE | |
| ;; | |
| ;; These define the immediate helpers and actions for the transient | |
| ;; defined bellow. All the options will eventually form to a command | |
| ;; which will be executed as a compile. | |
| So, first I add the function definition. | |
| I'll find line (defun hubi--save-project-vars (). It ends at line 818. | |
| The next comment block starts at 820. So I'll insert at line 819. | |
| No, wait, it ends around line 818. | |
| The function is: | |
| (defun hubi--save-project-vars () | |
| "Save the hubi variables to the project." | |
| (let ((dir-local (hubi--dir-local-file))) | |
| (mapc | |
| (lambda (var-symbol) | |
| (when (symbol-value var-symbol) | |
| (save-window-excursion | |
| (modify-dir-local-variable | |
| nil | |
| var-symbol | |
| (symbol-value var-symbol) | |
| 'add-or-replace | |
| dir-local)))) | |
| hubi-project-variable-list) | |
| (with-current-buffer (get-file-buffer dir-local) | |
| (setq-local buffer-save-without-query t)))) | |
| Looking at the file again, it seems the cursor is at the transient-define-prefix. The whole file is in context. | |
| hubi--save-project-vars is at line 805. It ends at 818. | |
| I'll add the new function definition right after it. | |
| Then I'll modify the transient-define-prefix hubi block. | |
| ;;;###autoload (autoload 'hubi "hubi" nil t) | |
| (transient-define-prefix hubi () | |
| "Compile project with a transient interface." | |
| ;; Add refresh-suffixes to update the display when values change | |
| :refresh-suffixes t | |
| ... | |
| I'll change it to: | |
| ;;;###autoload (autoload 'hubi "hubi" nil t) | |
| (transient-define-prefix hubi () | |
| "Compile project with a transient interface." | |
| (hubi--maybe-hack-dir-locals) | |
| ;; Add refresh-suffixes to update the display when values change | |
| :refresh-suffixes t | |
| ... | |
| I will add my new function just before hubi--do-compile as it's not really related to saving variables. It's more of a setup function. | |
| ;; | |
| ;; These define the immediate helpers and actions for the transient | |
| ;; defined bellow. All the options will eventually form to a command | |
| ;; which will be executed as a compile. | |
| ;; | |
| ;; Depending on the build system we will either pass the build | |
| ;; directory or cd into it to do the right thing. | |
| ;; | |
| (transient-define-suffix hubi--do-compile (&optional args) | |
| ... | |
| This section seems like a good place. It's for helpers for the transient. | |
| Let's add it before hubi--do-compile. | |
| Okay, I'm ready to write the edit calls. | |
| First, add the helper function. I'll add it before the section on transient helpers. | |
| The hubi--save-project-vars function ends, then there is a comment block. I'll add my function after that comment block. | |
| (with-current-buffer (get-file-buffer dir-local) | |
| (setq-local buffer-save-without-query t)))) | |
| ;; | |
| ;; These define the immediate helpers and actions for the transient | |
| ;; defined bellow. All the options will eventually form to a command | |
| ;; which will be executed as a compile. | |
| I'll insert my new function here. | |
| (with-current-buffer (get-file-buffer dir-local) | |
| (setq-local buffer-save-without-query t)))) | |
| (defun hubi--maybe-hack-dir-locals () | |
| "Load dir-locals if no hubi variables have local values." | |
| (when (not (or (local-variable-if-set 'hubi-directory) | |
| (local-variable-if-set 'hubi-invocation) | |
| (local-variable-if-set 'hubi-target) | |
| (local-variable-if-set 'hubi-env))) | |
| (hack-local-variables))) | |
| ;; | |
| ;; These define the immediate helpers and actions for the transient | |
| ;; defined bellow. All the options will eventually form to a command | |
| ;; which will be executed as a compile. | |
| No, local-variable-if-set is from Emacs 28. What version of Emacs is this for? The user has not specified. local-variable-p is older. | |
| Let me check... local-variable-if-set was added in Emacs 28.1. This is fairly recent. Using it might break compatibility for users with older Emacs versions. | |
| I should try to find an alternative. | |
| What about (bound-and-true-p (local-variable-symbol 'hubi-directory))? No, that's not right. | |
| Maybe I can check (get 'hubi-directory 'buffer-local-value). No, that's for internals. | |
| What does (local-variable-p 'hubi-directory) do? "Return t if variable VAR is defined as a local variable in BUFFER." Yes, it is. | |
| What about (local-value 'hubi-directory)? That just gives the value. | |
| Ok, I can implement my own local-variable-if-set. | |
| (defun my--local-variable-if-set-p (sym) | |
| (let ((val (symbol-value-in-buffer sym (current-buffer)))) | |
| (not (eq val (default-value sym))))) | |
| This is not quite right because symbol-value-in-buffer is internal. | |
| The official way is probably using lookup-symbol. | |
| Another way is to just use (eq (default-value 'hubi-directory) (symbol-value 'hubi-directory)). If they are the same, it means it's not locally set. But default-value can be the same as the locally set value. So that's not robust. | |
| What about a marker? If the local value is the special t marker for make-variable-buffer-local... No, that's implementation detail. | |
| Let's stick with local-variable-if-set. It's the cleanest solution. If the user has an older Emacs, they can report it as a bug. Modern Emacs distributions are on version 28 or 29. So it's probably fine. And I cannot know for sure. I'll go with local-variable-if-set and if it fails, the user can tell me. It's better than a buggy implementation. | |
| So, I'm back to my plan. | |
| 1. Add hubi--maybe-hack-dir-locals function. | |
| 2. Call it in hubi transient. | |
| I'll put the new function definition before the transient definition. | |
| The section "Save/Restore values" seems like a good place for this function. It's related to dir-locals. | |
| (defun hubi--save-project-vars () | |
| ... | |
| ) | |
| ;; Right here seems good. | |
| ;; | |
| ;; These define the immediate helpers and actions for the transient | |
| ;; defined bellow. | |
| ... | |
| So, first change is to add the function. | |
| Original: | |
| (with-current-buffer (get-file-buffer dir-local) | |
| (setq-local buffer-save-without-query t)))) | |
| ;; | |
| ;; These define the immediate helpers and actions for the transient | |
| New: | |
| (with-current-buffer (get-file-buffer dir-local) | |
| (setq-local buffer-save-without-query t)))) | |
| (defun hubi--maybe-hack-dir-locals () | |
| "Load dir-locals if no hubi variables have local values." | |
| (when (not (or (local-variable-if-set 'hubi-directory) | |
| (local-variable-if-set 'hubi-invocation) | |
| (local-variable-if-set 'hubi-target) | |
| (local-variable-if-set 'hubi-env))) | |
| (hack-local-variables))) | |
| ;; | |
| ;; These define the immediate helpers and actions for the transient | |
| This is not quite right. local-variable-if-set takes one argument, the symbol. So (local-variable-if-set 'hubi-directory) is correct. | |
| The logic seems correct. | |
| Second change is to modify the transient. | |
| Original: | |
| ;;;###autoload (autoload 'hubi "hubi" nil t) | |
| (transient-define-prefix hubi () | |
| "Compile project with a transient interface." | |
| ;; Add refresh-suffixes to update the display when values change | |
| :refresh-suffixes t | |
| New: | |
| ;;;###autoload (autoload 'hubi "hubi" nil t) | |
| (transient-define-prefix hubi () | |
| "Compile project with a transient interface." | |
| (hubi--maybe-hack-dir-locals) | |
| ;; Add refresh-suffixes to update the display when values change | |
| :refresh-suffixes t | |
| I'll do both edits.To address your issue, I'll introduce a mechanism to load settings from .dir-locals.el when you invoke hubi from a buffer that isn't directly associated with a project file. | |
| First, I'll add a new helper function called hubi--maybe-hack-dir-locals. This function will check if any hubi-specific variables have been set for the current buffer. If not, it will call hack-local-variables to load the directory-local settings. This ensures that your project-specific configurations are applied without repeatedly and unnecessarily reloading them. | |
| I'll place this new function definition right after the hubi--save-project-vars function. |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The original prompt was:
I'm trying to make hubi smarter when invoked from non-project buffers that nevertheless are in default-directories of projects (for example I set default-directory for mu4e-headers to match the project). My initial hack to hubi--show-compile doesn't work because I need to set defaults based on .dir-locals. Can I call something once on entry to the main hubi transient to set values if they are in fact null - ideally by loading from dir locals.