* About zcomplete [not found] <20220220040515.zum3iodtpscj23j3.ref@Ergus> @ 2022-02-20 4:05 ` Ergus 2022-02-20 10:12 ` Manuel Uberti 2022-02-20 11:11 ` Philip Kaludercic 0 siblings, 2 replies; 18+ messages in thread From: Ergus @ 2022-02-20 4:05 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel Hi recently I have been trying to move back to default completion. As I had many issues with fido and icomplete. The default completion system received a nice improvement recently with the completion-autoselect... and I am wondering a simple mode like this may be added to vanilla (or at least it gives an idea to a better lisper to implement something better, this is just a proof of concept.) ``` (require 'simple) (require 'minibuffer) (defvar-keymap zcomplete-map :doc "Keymap used in *Completions* on zcomplete" :parent completion-list-mode-map "z" nil "n" nil "p" nil "q" nil "g" nil "h" nil "DEL" nil ) (defun zcomplete--try-on-minibuffer () "Try to execute the binding on minibuffer." (switch-to-minibuffer) (if-let ((command (lookup-key (current-active-maps) (this-single-command-keys)))) (progn (minibuffer-hide-completions) (call-interactively command) t) ;; back to completions (switch-to-completions) nil)) (defun zcomplete--completions-pre-hook () "Try on minibuffer when the command is not in *Completions* map." (when (eq this-command 'undefined) (zcomplete--try-on-minibuffer))) (defun zcomplete--hack (data context signal) "Alternative to command-error-default-function. This will try to execute on minibuffer, else emits the error" (unless (and (string= (buffer-name) "*Completions*") (zcomplete--try-on-minibuffer)) (command-error-default-function data context signal))) (defun zcomplete--completions-setup-hook () "To call on completions setup." (add-hook 'pre-command-hook #'zcomplete--completions-pre-hook nil t) (setq-local command-error-function #'zcomplete--hack) (setq-local mode-line-format nil) (use-local-map zcomplete-map)) (define-minor-mode zcomplete-mode "Completion highlight mode to enable candidates highlight in the minibuffer." :global t :group 'minibuffer (if zcomplete-mode (progn (setq completion-auto-select t) ;; (overlay-put zcomplete-overlay 'face 'zcomplete) (add-hook 'completion-setup-hook #'zcomplete--completions-setup-hook t)) (remove-hook 'completion-setup-hook #'zcomplete--completions-setup-hook))) (provide 'zcomplete) ``` It lacks some features (like highlight the current candidate or automatically update completion buffers when visible) to be really a zsh-like feature, but at least we don't need to press C-g every time we want to edit the minibuffer. With this a tab shows the completions and goes there, and any attempt to edit or not defined command tries to execute on the minibuffer... Parts of this could be implemented with advises, but I know we try to avoid those on vanilla code. WDYT? Best, Ergus ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: About zcomplete 2022-02-20 4:05 ` About zcomplete Ergus @ 2022-02-20 10:12 ` Manuel Uberti 2022-02-20 10:14 ` Manuel Uberti 2022-02-20 10:54 ` Ergus 2022-02-20 11:11 ` Philip Kaludercic 1 sibling, 2 replies; 18+ messages in thread From: Manuel Uberti @ 2022-02-20 10:12 UTC (permalink / raw) To: Ergus; +Cc: emacs-devel On 20/02/22 05:05, Ergus wrote: > Hi recently I have been trying to move back to default completion. As > I had many issues with fido and icomplete. May I ask with issues did you have with fido? I've been using fido-vertical-mode for a long while now and I am kind of happy with it. -- Manuel Uberti www.manueluberti.eu ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: About zcomplete 2022-02-20 10:12 ` Manuel Uberti @ 2022-02-20 10:14 ` Manuel Uberti 2022-02-20 10:54 ` Ergus 1 sibling, 0 replies; 18+ messages in thread From: Manuel Uberti @ 2022-02-20 10:14 UTC (permalink / raw) To: emacs-devel On 20/02/22 11:12, Manuel Uberti wrote: > On 20/02/22 05:05, Ergus wrote: >> Hi recently I have been trying to move back to default completion. As >> I had many issues with fido and icomplete. > > May I ask with issues did you have with fido? I've been using fido-vertical-mode > for a long while now and I am kind of happy with it. > -- > Manuel Uberti > www.manueluberti.eu > I meant "what" issues, not "with" of course. -- Manuel Uberti www.manueluberti.eu ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: About zcomplete 2022-02-20 10:12 ` Manuel Uberti 2022-02-20 10:14 ` Manuel Uberti @ 2022-02-20 10:54 ` Ergus 2022-02-20 12:42 ` Manuel Uberti 1 sibling, 1 reply; 18+ messages in thread From: Ergus @ 2022-02-20 10:54 UTC (permalink / raw) To: emacs-devel, Manuel Uberti [-- Attachment #1: Type: text/plain, Size: 602 bytes --] Hi: #54042, #54058 and the lack of some features and customizations... On February 20, 2022 11:12:28 AM GMT+01:00, Manuel Uberti <manuel.uberti@inventati.org> wrote: >On 20/02/22 05:05, Ergus wrote: >> Hi recently I have been trying to move back to default completion. As >> I had many issues with fido and icomplete. > >May I ask with issues did you have with fido? I've been using fido-vertical-mode >for a long while now and I am kind of happy with it. > -- >Manuel Uberti >www.manueluberti.eu > -- Sent from my Android device with K-9 Mail. Please excuse my brevity. [-- Attachment #2: Type: text/html, Size: 1087 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: About zcomplete 2022-02-20 10:54 ` Ergus @ 2022-02-20 12:42 ` Manuel Uberti 0 siblings, 0 replies; 18+ messages in thread From: Manuel Uberti @ 2022-02-20 12:42 UTC (permalink / raw) To: Ergus, emacs-devel On 20/02/22 11:54, Ergus wrote: > Hi: > > #54042, #54058 and the lack of some features and customizations... Interesting, thanks. You're probably aware of this already, but to work around #54042 I added: '((file (styles basic partial-completion))) To `completion-category-overrides'. -- Manuel Uberti www.manueluberti.eu ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: About zcomplete 2022-02-20 4:05 ` About zcomplete Ergus 2022-02-20 10:12 ` Manuel Uberti @ 2022-02-20 11:11 ` Philip Kaludercic 2022-02-20 13:27 ` Ergus 1 sibling, 1 reply; 18+ messages in thread From: Philip Kaludercic @ 2022-02-20 11:11 UTC (permalink / raw) To: Ergus; +Cc: emacs-devel, Juri Linkov Ergus <spacibba@aol.com> writes: > Hi recently I have been trying to move back to default completion. As > I had many issues with fido and icomplete. > > The default completion system received a nice improvement recently with > the completion-autoselect... and I am wondering a simple mode like > this may be added to vanilla (or at least it gives an idea to a better > lisper to implement something better, this is just a proof of concept.) > > ``` > (require 'simple) > (require 'minibuffer) > > (defvar-keymap zcomplete-map > :doc "Keymap used in *Completions* on zcomplete" > :parent completion-list-mode-map > "z" nil > "n" nil > "p" nil > "q" nil > "g" nil > "h" nil > "DEL" nil > ) When completion-auto-select was first added, there was a discussion about adding automatic narrowing in the *Completions* buffer. Given a mode like zcomplete, that decides to unbind all single-character bindings, this might be possible (as an alternative to what you do in zcomplete--try-on-minibuffer). Whether or not this should be coupled to removing the mode line of the completion buffer is a different question. > (defun zcomplete--try-on-minibuffer () > "Try to execute the binding on minibuffer." > (switch-to-minibuffer) > (if-let ((command (lookup-key (current-active-maps) > (this-single-command-keys)))) > (progn > (minibuffer-hide-completions) > (call-interactively command) > t) > ;; back to completions > (switch-to-completions) > nil)) > > (defun zcomplete--completions-pre-hook () > "Try on minibuffer when the command is not in *Completions* map." > (when (eq this-command 'undefined) > (zcomplete--try-on-minibuffer))) > > (defun zcomplete--hack (data context signal) > "Alternative to command-error-default-function. > This will try to execute on minibuffer, else emits the error" > (unless (and (string= (buffer-name) "*Completions*") > (zcomplete--try-on-minibuffer)) > (command-error-default-function data context signal))) > > (defun zcomplete--completions-setup-hook () > "To call on completions setup." > (add-hook 'pre-command-hook #'zcomplete--completions-pre-hook nil t) > > (setq-local command-error-function #'zcomplete--hack) > (setq-local mode-line-format nil) > (use-local-map zcomplete-map)) > > (define-minor-mode zcomplete-mode > "Completion highlight mode to enable candidates highlight in the minibuffer." > :global t > :group 'minibuffer > > (if zcomplete-mode > (progn > (setq completion-auto-select t) This should probably be reverted when zcomplete-mode is disabled. > ;; (overlay-put zcomplete-overlay 'face 'zcomplete) > (add-hook 'completion-setup-hook #'zcomplete--completions-setup-hook t)) > > (remove-hook 'completion-setup-hook #'zcomplete--completions-setup-hook))) > > (provide 'zcomplete) > ``` > > It lacks some features (like highlight the current candidate or > automatically update completion buffers when visible) to be really a > zsh-like feature, but at least we don't need to press C-g every time we > want to edit the minibuffer. > > With this a tab shows the completions and goes there, and any attempt to > edit or not defined command tries to execute on the minibuffer... > > Parts of this could be implemented with advises, but I know we try to > avoid those on vanilla code. If something like this would be added to the core, it would be better to patch the relevant sections directly. > WDYT? > Best, > Ergus > > -- Philip Kaludercic ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: About zcomplete 2022-02-20 11:11 ` Philip Kaludercic @ 2022-02-20 13:27 ` Ergus 2022-02-21 10:35 ` Philip Kaludercic 0 siblings, 1 reply; 18+ messages in thread From: Ergus @ 2022-02-20 13:27 UTC (permalink / raw) To: Philip Kaludercic; +Cc: emacs-devel, Juri Linkov On Sun, Feb 20, 2022 at 11:11:00AM +0000, Philip Kaludercic wrote: >Ergus <spacibba@aol.com> writes: > >> Hi recently I have been trying to move back to default completion. As >> I had many issues with fido and icomplete. >> >> The default completion system received a nice improvement recently with >> the completion-autoselect... and I am wondering a simple mode like >> this may be added to vanilla (or at least it gives an idea to a better >> lisper to implement something better, this is just a proof of concept.) >> >> ``` >> (require 'simple) >> (require 'minibuffer) >> >> (defvar-keymap zcomplete-map >> :doc "Keymap used in *Completions* on zcomplete" >> :parent completion-list-mode-map >> "z" nil >> "n" nil >> "p" nil >> "q" nil >> "g" nil >> "h" nil >> "DEL" nil >> ) > >When completion-auto-select was first added, there was a discussion >about adding automatic narrowing in the *Completions* buffer. Given a >mode like zcomplete, that decides to unbind all single-character >bindings, this might be possible (as an alternative to what you do in >zcomplete--try-on-minibuffer). > >Whether or not this should be coupled to removing the mode line of the >completion buffer is a different question. > Actually a more `urgent` thing in my opinion may be to allow *Completions* to update without needing to narrow first. Then I could add a post-command-hook in the minibuffer to update *Completions* when it is visible. With that we only need a highlight and the zsh experience may be almost done with minimal changes. >> (defun zcomplete--try-on-minibuffer () >> "Try to execute the binding on minibuffer." >> (switch-to-minibuffer) >> (if-let ((command (lookup-key (current-active-maps) >> (this-single-command-keys)))) >> (progn >> (minibuffer-hide-completions) >> (call-interactively command) >> t) >> ;; back to completions >> (switch-to-completions) >> nil)) >> >> (defun zcomplete--completions-pre-hook () >> "Try on minibuffer when the command is not in *Completions* map." >> (when (eq this-command 'undefined) >> (zcomplete--try-on-minibuffer))) >> >> (defun zcomplete--hack (data context signal) >> "Alternative to command-error-default-function. >> This will try to execute on minibuffer, else emits the error" >> (unless (and (string= (buffer-name) "*Completions*") >> (zcomplete--try-on-minibuffer)) >> (command-error-default-function data context signal))) >> >> (defun zcomplete--completions-setup-hook () >> "To call on completions setup." >> (add-hook 'pre-command-hook #'zcomplete--completions-pre-hook nil t) >> >> (setq-local command-error-function #'zcomplete--hack) >> (setq-local mode-line-format nil) >> (use-local-map zcomplete-map)) >> >> (define-minor-mode zcomplete-mode >> "Completion highlight mode to enable candidates highlight in the minibuffer." >> :global t >> :group 'minibuffer >> >> (if zcomplete-mode >> (progn >> (setq completion-auto-select t) > >This should probably be reverted when zcomplete-mode is disabled. > Agree. But we need to cache the original value tho... I have been thinking to implement a general solution for that issue similar to connection-local-variables, because it is a general issue many packages need to deal with. >> ;; (overlay-put zcomplete-overlay 'face 'zcomplete) >> (add-hook 'completion-setup-hook #'zcomplete--completions-setup-hook t)) >> >> (remove-hook 'completion-setup-hook #'zcomplete--completions-setup-hook))) >> >> (provide 'zcomplete) >> ``` >> >> It lacks some features (like highlight the current candidate or >> automatically update completion buffers when visible) to be really a >> zsh-like feature, but at least we don't need to press C-g every time we >> want to edit the minibuffer. >> >> With this a tab shows the completions and goes there, and any attempt to >> edit or not defined command tries to execute on the minibuffer... >> >> Parts of this could be implemented with advises, but I know we try to >> avoid those on vanilla code. > >If something like this would be added to the core, it would be better to >patch the relevant sections directly. > >> WDYT? >> Best, >> Ergus >> >> > >-- > Philip Kaludercic > ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: About zcomplete 2022-02-20 13:27 ` Ergus @ 2022-02-21 10:35 ` Philip Kaludercic 2022-02-21 12:22 ` Ergus 2022-02-21 15:35 ` Setting global variables (was: About zcomplete) Stefan Monnier 0 siblings, 2 replies; 18+ messages in thread From: Philip Kaludercic @ 2022-02-21 10:35 UTC (permalink / raw) To: Ergus; +Cc: Juri Linkov, emacs-devel Ergus <spacibba@aol.com> writes: > On Sun, Feb 20, 2022 at 11:11:00AM +0000, Philip Kaludercic wrote: > >>When completion-auto-select was first added, there was a discussion >>about adding automatic narrowing in the *Completions* buffer. Given a >>mode like zcomplete, that decides to unbind all single-character >>bindings, this might be possible (as an alternative to what you do in >>zcomplete--try-on-minibuffer). >> >>Whether or not this should be coupled to removing the mode line of the >>completion buffer is a different question. > > Actually a more `urgent` thing in my opinion may be to allow > *Completions* to update without needing to narrow first. Then I could > add a post-command-hook in the minibuffer to update *Completions* when > it is visible. I am not certain what you mean here? Just to clarify, what I am imagining is a isearch-like interface that updates the prompt and the *Completions* buffer. > With that we only need a highlight and the zsh experience may be almost > done with minimal changes. I am unfamiliar with zsh, how does it differ from say bash? >>This should probably be reverted when zcomplete-mode is disabled. > > Agree. But we need to cache the original value tho... I have been > thinking to implement a general solution for that issue similar to > connection-local-variables, because it is a general issue many packages > need to deal with. I guess this is only of the issue that is so easy to solve on a case-by-case basis (e.g. by setting a symbol property) that nobody has bothered to write a general solution (e.g. by adding a keyword to define-minor-mode that specifies what variables/user options to set when enabled). -- Philip Kaludercic ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: About zcomplete 2022-02-21 10:35 ` Philip Kaludercic @ 2022-02-21 12:22 ` Ergus 2022-02-21 15:35 ` Setting global variables (was: About zcomplete) Stefan Monnier 1 sibling, 0 replies; 18+ messages in thread From: Ergus @ 2022-02-21 12:22 UTC (permalink / raw) To: Philip Kaludercic; +Cc: emacs-devel, Juri Linkov On Mon, Feb 21, 2022 at 10:35:28AM +0000, Philip Kaludercic wrote: >Ergus <spacibba@aol.com> writes: > >> On Sun, Feb 20, 2022 at 11:11:00AM +0000, Philip Kaludercic wrote: >> >>>When completion-auto-select was first added, there was a discussion >>>about adding automatic narrowing in the *Completions* buffer. Given a >>>mode like zcomplete, that decides to unbind all single-character >>>bindings, this might be possible (as an alternative to what you do in >>>zcomplete--try-on-minibuffer). >>> >>>Whether or not this should be coupled to removing the mode line of the >>>completion buffer is a different question. >> >> Actually a more `urgent` thing in my opinion may be to allow >> *Completions* to update without needing to narrow first. Then I could >> add a post-command-hook in the minibuffer to update *Completions* when >> it is visible. > >I am not certain what you mean here? Just to clarify, what I am >imagining is a isearch-like interface that updates the prompt and the >*Completions* buffer. > In the current implementation the *Completions* buffer is updated under tab 1) first tab completes common, 2) second one shows completions. If completions are visible then a first tab hides *Completions*, and then 1) and 2) Completions are only updated if the common part is completed and Completions windows is not visible. When we insert more text in the minibuffer with Completions visible what I do now is to hide the *Completions* window directly because they may be outdated. Calling the completion function in post command hook inserts more text in the minibuffer (to complete common), which is undesired. And the Completions are not updated if they are visible (at least I haven't found a way) >> With that we only need a highlight and the zsh experience may be almost >> done with minimal changes. > >I am unfamiliar with zsh, how does it differ from say bash? > In zsh 1 tab completes common and show completions candidates (may be configured to do in the first tab or wait for a second one, but we don't really care). The key difference is that with completions visible if we type a new letter then the completion list updates immediately and if there is a common part is only completed with a new tab. >>>This should probably be reverted when zcomplete-mode is disabled. >> >> Agree. But we need to cache the original value tho... I have been >> thinking to implement a general solution for that issue similar to >> connection-local-variables, because it is a general issue many packages >> need to deal with. > >I guess this is only of the issue that is so easy to solve on a >case-by-case basis (e.g. by setting a symbol property) that nobody has >bothered to write a general solution (e.g. by adding a keyword to >define-minor-mode that specifies what variables/user options to set when >enabled). > Look at issue #54074 and Juri's comment. I actually find that this is a very common and repeated issue and duplicated code in many packages around... >-- > Philip Kaludercic Best, Ergus ^ permalink raw reply [flat|nested] 18+ messages in thread
* Setting global variables (was: About zcomplete) 2022-02-21 10:35 ` Philip Kaludercic 2022-02-21 12:22 ` Ergus @ 2022-02-21 15:35 ` Stefan Monnier 2022-02-21 16:57 ` Ergus ` (2 more replies) 1 sibling, 3 replies; 18+ messages in thread From: Stefan Monnier @ 2022-02-21 15:35 UTC (permalink / raw) To: Philip Kaludercic; +Cc: Ergus, Juri Linkov, emacs-devel > I guess this is only of the issue that is so easy to solve on a > case-by-case basis (e.g. by setting a symbol property) that nobody has > bothered to write a general solution (e.g. by adding a keyword to > define-minor-mode that specifies what variables/user options to set when > enabled). FWIW, I've been toying with the idea of adding a kind of "advice" mechanism for variables. Basically associate with every variable a base value and a list of functions that modify it. Then minor modes can add a function to the list (which would implicitly update the var's effective value) when enabled and then remove it afterwards. Stefan ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Setting global variables (was: About zcomplete) 2022-02-21 15:35 ` Setting global variables (was: About zcomplete) Stefan Monnier @ 2022-02-21 16:57 ` Ergus 2022-02-21 23:33 ` Case Duckworth 2022-02-22 5:14 ` Richard Stallman 2 siblings, 0 replies; 18+ messages in thread From: Ergus @ 2022-02-21 16:57 UTC (permalink / raw) To: Stefan Monnier; +Cc: Philip Kaludercic, Juri Linkov, emacs-devel On Mon, Feb 21, 2022 at 10:35:43AM -0500, Stefan Monnier wrote: >> I guess this is only of the issue that is so easy to solve on a >> case-by-case basis (e.g. by setting a symbol property) that nobody has >> bothered to write a general solution (e.g. by adding a keyword to >> define-minor-mode that specifies what variables/user options to set when >> enabled). > >FWIW, I've been toying with the idea of adding a kind of "advice" >mechanism for variables. > >Basically associate with every variable a base value and a list of >functions that modify it. Then minor modes can add a function to the >list (which would implicitly update the var's effective value) when >enabled and then remove it afterwards. > > > Stefan > This actually sounds very interesting... Maybe you could suggest it in #54074 ... My idea was actually to have an interface like the one of use-packages in define-minor mode... for customs (vars), hooks and bindings... so disabling the mode automatically restores the variables, removes the hooks and cleans the bindings... But in the background either your proposal or Juri's looks fine... ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Setting global variables (was: About zcomplete) 2022-02-21 15:35 ` Setting global variables (was: About zcomplete) Stefan Monnier 2022-02-21 16:57 ` Ergus @ 2022-02-21 23:33 ` Case Duckworth 2022-02-22 5:14 ` Richard Stallman 2 siblings, 0 replies; 18+ messages in thread From: Case Duckworth @ 2022-02-21 23:33 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel I just want to say that some kind of advice for variables would be absolutely perfect. Basically every variable could be a "stack" that could be manipulated at will, giving a useful combination of lexical & dynamic scope ... I Think? Anyway it sounds GREAT :D -- Case Duckworth ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Setting global variables (was: About zcomplete) 2022-02-21 15:35 ` Setting global variables (was: About zcomplete) Stefan Monnier 2022-02-21 16:57 ` Ergus 2022-02-21 23:33 ` Case Duckworth @ 2022-02-22 5:14 ` Richard Stallman 2022-02-22 12:35 ` Eli Zaretskii 2022-02-22 13:04 ` Setting global variables Stefan Monnier 2 siblings, 2 replies; 18+ messages in thread From: Richard Stallman @ 2022-02-22 5:14 UTC (permalink / raw) To: Stefan Monnier; +Cc: philipk, emacs-devel, spacibba, juri [[[ To any NSA and FBI agents reading my email: please consider ]]] [[[ whether defending the US Constitution against all enemies, ]]] [[[ foreign or domestic, requires you to follow Snowden's example. ]]] > FWIW, I've been toying with the idea of adding a kind of "advice" > mechanism for variables. > Basically associate with every variable a base value and a list of > functions that modify it. Then minor modes can add a function to the > list (which would implicitly update the var's effective value) when > enabled and then remove it afterwards. I'm not sure what that last sentence means. Are you proposing a low-level mechanism that would take specified actions whenever the variable gets set? Or a Lisp-level facility that would achieve similar results? -- Dr Richard Stallman (https://stallman.org) Chief GNUisance of the GNU Project (https://gnu.org) Founder, Free Software Foundation (https://fsf.org) Internet Hall-of-Famer (https://internethalloffame.org) ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Setting global variables (was: About zcomplete) 2022-02-22 5:14 ` Richard Stallman @ 2022-02-22 12:35 ` Eli Zaretskii 2022-02-22 13:04 ` Setting global variables Stefan Monnier 1 sibling, 0 replies; 18+ messages in thread From: Eli Zaretskii @ 2022-02-22 12:35 UTC (permalink / raw) To: rms; +Cc: philipk, juri, spacibba, monnier, emacs-devel > From: Richard Stallman <rms@gnu.org> > Date: Tue, 22 Feb 2022 00:14:29 -0500 > Cc: philipk@posteo.net, emacs-devel@gnu.org, spacibba@aol.com, juri@linkov.net > > I'm not sure what that last sentence means. Are you proposing a > low-level mechanism that would take specified actions whenever the > variable gets set? If this is the proposal (I didn't interpret it that way), then we already have such a feature: add-variable-watcher. ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Setting global variables 2022-02-22 5:14 ` Richard Stallman 2022-02-22 12:35 ` Eli Zaretskii @ 2022-02-22 13:04 ` Stefan Monnier 2022-02-24 4:50 ` Richard Stallman 1 sibling, 1 reply; 18+ messages in thread From: Stefan Monnier @ 2022-02-22 13:04 UTC (permalink / raw) To: Richard Stallman; +Cc: philipk, spacibba, juri, emacs-devel > > Basically associate with every variable a base value and a list of > > functions that modify it. Then minor modes can add a function to the > > list (which would implicitly update the var's effective value) when > > enabled and then remove it afterwards. > I'm not sure what that last sentence means. Are you proposing a > low-level mechanism that would take specified actions whenever the > variable gets set? No, because at that level we lack the needed information (basically, the *intention* behind the new value). > Or a Lisp-level facility that would achieve similar results? Yes, that. The idea is very much like advice-add/remove but for variables instead of functions. Stefan ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Setting global variables 2022-02-22 13:04 ` Setting global variables Stefan Monnier @ 2022-02-24 4:50 ` Richard Stallman 2022-02-25 18:01 ` Stefan Monnier 0 siblings, 1 reply; 18+ messages in thread From: Richard Stallman @ 2022-02-24 4:50 UTC (permalink / raw) To: Stefan Monnier; +Cc: philipk, emacs-devel, spacibba, juri [[[ To any NSA and FBI agents reading my email: please consider ]]] [[[ whether defending the US Constitution against all enemies, ]]] [[[ foreign or domestic, requires you to follow Snowden's example. ]]] > The idea is very much like advice-add/remove but for variables instead > of functions. How would it work? Implementing advice is conceptually simple: you want to asvise `foo', build a new definition for `foo'. For variable `bar', is your ides to advise each function that uses `bar'? -- Dr Richard Stallman (https://stallman.org) Chief GNUisance of the GNU Project (https://gnu.org) Founder, Free Software Foundation (https://fsf.org) Internet Hall-of-Famer (https://internethalloffame.org) ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Setting global variables 2022-02-24 4:50 ` Richard Stallman @ 2022-02-25 18:01 ` Stefan Monnier 2022-02-26 4:52 ` Richard Stallman 0 siblings, 1 reply; 18+ messages in thread From: Stefan Monnier @ 2022-02-25 18:01 UTC (permalink / raw) To: Richard Stallman; +Cc: philipk, spacibba, juri, emacs-devel > > The idea is very much like advice-add/remove but for variables instead > > of functions. > How would it work? However we decide it should. > is your ides to advise each function that uses `bar'? I don't really know. Last time I took a more serious look at it, I ended up with the code below. Stefan ;;; Changing variables in general (not just function-valued ones) ;; TODO: Make it work for arbitrary gv-places? ;; TODO: Maybe use it or something similar to keep track of effects of ;; loading a file (where `id' would be the file name)? (defun advice-var--sym (var) (or (get var 'advice--var) (let ((sym (make-symbol "fun"))) (put var 'advice--var sym) ;; FIXME: We store the ground value in the function cell so that it can ;; be easily accessed/changed without having to search for it hidden in ;; the middle of a function. (fset sym (default-value var)) (set sym (lambda () (symbol-function sym))) sym))) (defun advice-var--make-local (var sym) (when (and (not (local-variable-p sym)) (local-variable-p var)) (add-function :override (local sym) ;; FIXME: Should we store this value in a more accessible ;; place, like we do for the global default? (let ((lv (symbol-value var))) (lambda () lv))))) (defun advice-var--refresh (var sym) ;; (cl-assert (eq sym (advice-var--sym var))) (if (local-variable-p sym) (make-local-variable var) (kill-local-variable var)) (set var (funcall (symbol-value sym)))) (defun advice-var-add (var f &optional id local) (let ((sym (advice-var--sym var)) ;; FIXME: This small function which calls two other functions, combined ;; with the advice object in which it'll be placed, results in "many" ;; small functions calling other small functions. ;; This is not handled efficiently by our ELisp engine, neither in ;; terms of space nor in terms of time. (advice (lambda (orig-fun) (funcall f (funcall orig-fun)))) (props (if id `((name . ,id))))) (when local (advice-var--make-local var sym)) (if local (add-function :around (local sym) advice props) (add-function :around (symbol-value sym) advice props)) (advice-var--refresh var sym))) (defun advice-var-set (var val &optional id local) (let ((sym (advice-var--sym var)) (props (if id `((name . ,id))))) (when local (advice-var--make-local var sym)) (if local (add-function :override (local sym) (lambda () val) props) (add-function :override (symbol-value sym) (lambda () val) props)) (advice-var--refresh var sym))) (defun advice-var-unset (var f-or-id &optional local) (let ((sym (advice-var--sym var))) (if local (remove-function (local sym) f-or-id) (remove-function (symbol-value sym) f-or-id)) (advice-var--refresh var sym))) ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Setting global variables 2022-02-25 18:01 ` Stefan Monnier @ 2022-02-26 4:52 ` Richard Stallman 0 siblings, 0 replies; 18+ messages in thread From: Richard Stallman @ 2022-02-26 4:52 UTC (permalink / raw) To: Stefan Monnier; +Cc: philipk, emacs-devel, spacibba, juri [[[ To any NSA and FBI agents reading my email: please consider ]]] [[[ whether defending the US Constitution against all enemies, ]]] [[[ foreign or domestic, requires you to follow Snowden's example. ]]] > > > The idea is very much like advice-add/remove but for variables instead > > > of functions. > > How would it work? > However we decide it should. When you come up with a plan, would you please tell it to me? -- Dr Richard Stallman (https://stallman.org) Chief GNUisance of the GNU Project (https://gnu.org) Founder, Free Software Foundation (https://fsf.org) Internet Hall-of-Famer (https://internethalloffame.org) ^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2022-02-26 4:52 UTC | newest] Thread overview: 18+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <20220220040515.zum3iodtpscj23j3.ref@Ergus> 2022-02-20 4:05 ` About zcomplete Ergus 2022-02-20 10:12 ` Manuel Uberti 2022-02-20 10:14 ` Manuel Uberti 2022-02-20 10:54 ` Ergus 2022-02-20 12:42 ` Manuel Uberti 2022-02-20 11:11 ` Philip Kaludercic 2022-02-20 13:27 ` Ergus 2022-02-21 10:35 ` Philip Kaludercic 2022-02-21 12:22 ` Ergus 2022-02-21 15:35 ` Setting global variables (was: About zcomplete) Stefan Monnier 2022-02-21 16:57 ` Ergus 2022-02-21 23:33 ` Case Duckworth 2022-02-22 5:14 ` Richard Stallman 2022-02-22 12:35 ` Eli Zaretskii 2022-02-22 13:04 ` Setting global variables Stefan Monnier 2022-02-24 4:50 ` Richard Stallman 2022-02-25 18:01 ` Stefan Monnier 2022-02-26 4:52 ` Richard Stallman
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.