Re: [Matlab-emacs-discuss] completion and goto-function in matlab-mode (Doom emacs)
Hi Karthik, Thanks for the update and explanation. I finally had some time to sit with your code, try it out in a few situations, and teach myself how xref works. I haven't had much opportunity to learn all the new stuff in eieio that it uses, so that was nice. I created matlab-xref.el on the shellcomplete branch which includes a tweaked version of your code. I included an xref engine that will do local symbol lookups for local functions and the like. Combined, with the shell version, you can get to most places quickly. I think this is a pretty good start. I've already found it changed the way I do navigation. Very nice. Eric On 12/23/20 5:04 AM, Karthik Chikmagalur wrote: Hi Eric, I did look at the elisp backend which it advertised as the prime example. That one is quite large compared to your patch. Do you think the below would expand out to be much larger? I'm considering if xref support would move into it's own file or not. The xref support for MATLAB in my patch is very short (relatively) because - I wrote it as a wrapper around `matlab-shell-which-fcn', which does the heavy lifing of finding the function in question. Matlab-shell already has support for jumping to definitions so I reused it. The downside is that matlab-shell needs to be running for xref support to work. This is not ideal, but the alternative is to write code to find function definitions from scratch. - Only jump to definition is implemented. Two other xref functions: `xref-backend-apropos' and `xref-find-references', are not implemented at all. I want to look into adding these, but I'm not sure right now how to go about it. I also note that the elisp version doesn't use require for xref, and your patch depends on the feature existing when the code loads. I think it does so via: (declare-function xref-make "xref" (summary location)) Will that work here too? I think `declare-function' keeps the byte-compiler from complaining and doesn't do much else. This should help here, though, and checking if xref is loaded should be unnecessary. In summary, a slightly modified version of this patch can be included as preliminary xref support for matlab-mode. It can be its own file if it's expected to be expanded in the future with `xref-find-references' and other functionality, and prehaps written in a way as to not require matlab-shell to be running. Attached is a patch (as a separate file) with some minor modifications from last time. For it to be integrated into matlab-mode, one other piece of configuration is needed: (add-hook 'xref-backend-definitions #'matlab-shell-xref-activate) This needs to be added in the matlab-mode major mode definition in `define-derived-mode matlab-mode' in matlab.el. Karthik ___ Matlab-emacs-discuss mailing list Matlab-emacs-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss
Re: [Matlab-emacs-discuss] completion and goto-function in matlab-mode (Doom emacs)
Hi Jonathan, I tried using: M-x matlab-shell RET M-x company-mode RET then @ matlab prompt: >> fo M-x company-matlab-shell RET to simulate what you have in your stack trace below. I get a yellow popup with completions I expect in it. I can pick one and it then inserts the completion correctly. I tried this in Emacs 26.3 as installed by Ubuntu, and also 28.0.50 as downloaded from git yesterday morning. I tend to run my Emacs as stock as possible so I don't accidentally create dependencies on random tools, so I'm not familiar with a more complex company mode setup. Due to the nature of using MATLAB Shell, I recommend looking at the value of `comint-prompt-read-only' to see if that might be involved. It is nil by default in my Emacsen, and matlab-shell doesn't set it because I do a lot of fiddling with the buffer in the background. If it were t, I would imagine a range of other things not working either though. That's pretty much all I can think of. Sorry I can't be more helpful. :( Eric On 1/6/21 5:50 AM, Jonathan Sahar wrote: Hi, I'm still getting the same error message with the updated version of the repository... the stack trace I get is: ``` Debugger entered--Lisp error: (error "Company: backend company-matlab-shell error \"Text is read-only\" with args (prefix)") signal(error ("Company: backend company-matlab-shell error \"Text is read-only\" with args (prefix)")) error("Company: backend %s error \"%s\" with args %s" company-matlab-shell "Text is read-only" (prefix)) company-call-backend-raw(prefix) apply(company-call-backend-raw prefix) company--force-sync(company-call-backend-raw (prefix) company-matlab-shell) company-call-backend(prefix) company--begin-new() company--perform() company-auto-begin() company-manual-begin() #f(compiled-function (backend &optional callback) "Start a completion at point using BACKEND." (interactive #f(compiled-function () #)) #)(company-matlab-shell) apply(#f(compiled-function (backend &optional callback) "Start a completion at point using BACKEND." (interactive #f(compiled-function () #)) #) company-matlab-shell) company-begin-backend(company-matlab-shell) company-matlab-shell(interactive) funcall-interactively(company-matlab-shell interactive) ``` and the output in the console is: ``` >> emacsdocomplete('all') emacs_completions_output = java.lang.String[]: 'all' 'allchild' 'allElectrodes' 'allfeasible' 'allMuPADNotebooks' ``` which is the same output that I get by running M-x matlab-complete-symbol, if that helps to make sense of things. Thanks, Jonathan ___ Matlab-emacs-discuss mailing list Matlab-emacs-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss
Re: [Matlab-emacs-discuss] completion and goto-function in matlab-mode (Doom emacs)
Dear Jonathan, I am running Doom Emacs and had the same issue. The problem is that the temporary output should be removed, but the lines in the shell-buffer have a special read-only mode. The work-around is to set `inhibit-read-only`. So what solved it: (defadvice! inhibit-real-only-a (oldfun &rest r) "Temporary remove read-only lines in shell buffer" :around#'matlab-shell-collect-command-output (let ((inhibit-read-only t)) (apply oldfun r))) Best regards, Haik 17.01.2021 20:20 Eric Ludlam kirjutas: Hi Jonathan, I tried using: M-x matlab-shell RET M-x company-mode RET then @ matlab prompt: >> fo M-x company-matlab-shell RET to simulate what you have in your stack trace below. I get a yellow popup with completions I expect in it. I can pick one and it then inserts the completion correctly. I tried this in Emacs 26.3 as installed by Ubuntu, and also 28.0.50 as downloaded from git yesterday morning. I tend to run my Emacs as stock as possible so I don't accidentally create dependencies on random tools, so I'm not familiar with a more complex company mode setup. Due to the nature of using MATLAB Shell, I recommend looking at the value of `comint-prompt-read-only' to see if that might be involved. It is nil by default in my Emacsen, and matlab-shell doesn't set it because I do a lot of fiddling with the buffer in the background. If it were t, I would imagine a range of other things not working either though. That's pretty much all I can think of. Sorry I can't be more helpful. :( Eric On 1/6/21 5:50 AM, Jonathan Sahar wrote: Hi, I'm still getting the same error message with the updated version of the repository... the stack trace I get is: ``` Debugger entered--Lisp error: (error "Company: backend company-matlab-shell error \"Text is read-only\" with args (prefix)") signal(error ("Company: backend company-matlab-shell error \"Text is read-only\" with args (prefix)")) error("Company: backend %s error \"%s\" with args %s" company-matlab-shell "Text is read-only" (prefix)) company-call-backend-raw(prefix) apply(company-call-backend-raw prefix) company--force-sync(company-call-backend-raw (prefix) company-matlab-shell) company-call-backend(prefix) company--begin-new() company--perform() company-auto-begin() company-manual-begin() #f(compiled-function (backend &optional callback) "Start a completion at point using BACKEND." (interactive #f(compiled-function () #)) #0x36c7e49>)(company-matlab-shell) apply(#f(compiled-function (backend &optional callback) "Start a completion at point using BACKEND." (interactive #f(compiled-function () #)) #) company-matlab-shell) company-begin-backend(company-matlab-shell) company-matlab-shell(interactive) funcall-interactively(company-matlab-shell interactive) ``` and the output in the console is: ``` >> emacsdocomplete('all') emacs_completions_output = java.lang.String[]: 'all' 'allchild' 'allElectrodes' 'allfeasible' 'allMuPADNotebooks' ``` which is the same output that I get by running M-x matlab-complete-symbol, if that helps to make sense of things. Thanks, Jonathan ___ Matlab-emacs-discuss mailing list Matlab-emacs-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss ___ Matlab-emacs-discuss mailing list Matlab-emacs-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss
Re: [Matlab-emacs-discuss] completion and goto-function in matlab-mode (Doom emacs)
Thanks Haik. That implies a patch like this will fix the issue... ? Do you know what is being set to read-only and why? A better patch might disable whatever that is since other code may need something similar, and it would be better to fix the source than add little patches like this around. Eric -- diff --git a/matlab-shell.el b/matlab-shell.el index b2943d8..0357119 100644 --- a/matlab-shell.el +++ b/matlab-shell.el @@ -1686,7 +1686,8 @@ This uses the lookfor command to find viable commands." It's output is returned as a string with no face properties. The text output of the command is removed from the MATLAB buffer so there will be no indication that it ran." - (let ((msbn (matlab-shell-buffer-barf-not-running)) + (let ((inhibit-read-only t) + (msbn (matlab-shell-buffer-barf-not-running)) (matlab-shell-suppress-prompt-hooks t)) ;; We are unable to use save-excursion to save point position because we are ;; manipulating the *MATLAB* buffer by erasing the current text typed at the On 1/17/21 2:35 PM, Haik Silm wrote: Dear Jonathan, I am running Doom Emacs and had the same issue. The problem is that the temporary output should be removed, but the lines in the shell-buffer have a special read-only mode. The work-around is to set `inhibit-read-only`. So what solved it: (defadvice! inhibit-real-only-a (oldfun &rest r) "Temporary remove read-only lines in shell buffer" :around#'matlab-shell-collect-command-output (let ((inhibit-read-only t)) (apply oldfun r))) Best regards, Haik 17.01.2021 20:20 Eric Ludlam kirjutas: Hi Jonathan, I tried using: M-x matlab-shell RET M-x company-mode RET then @ matlab prompt: >> fo M-x company-matlab-shell RET to simulate what you have in your stack trace below. I get a yellow popup with completions I expect in it. I can pick one and it then inserts the completion correctly. I tried this in Emacs 26.3 as installed by Ubuntu, and also 28.0.50 as downloaded from git yesterday morning. I tend to run my Emacs as stock as possible so I don't accidentally create dependencies on random tools, so I'm not familiar with a more complex company mode setup. Due to the nature of using MATLAB Shell, I recommend looking at the value of `comint-prompt-read-only' to see if that might be involved. It is nil by default in my Emacsen, and matlab-shell doesn't set it because I do a lot of fiddling with the buffer in the background. If it were t, I would imagine a range of other things not working either though. That's pretty much all I can think of. Sorry I can't be more helpful. :( Eric On 1/6/21 5:50 AM, Jonathan Sahar wrote: Hi, I'm still getting the same error message with the updated version of the repository... the stack trace I get is: ``` Debugger entered--Lisp error: (error "Company: backend company-matlab-shell error \"Text is read-only\" with args (prefix)") signal(error ("Company: backend company-matlab-shell error \"Text is read-only\" with args (prefix)")) error("Company: backend %s error \"%s\" with args %s" company-matlab-shell "Text is read-only" (prefix)) company-call-backend-raw(prefix) apply(company-call-backend-raw prefix) company--force-sync(company-call-backend-raw (prefix) company-matlab-shell) company-call-backend(prefix) company--begin-new() company--perform() company-auto-begin() company-manual-begin() #f(compiled-function (backend &optional callback) "Start a completion at point using BACKEND." (interactive #f(compiled-function () #)) #)(company-matlab-shell) apply(#f(compiled-function (backend &optional callback) "Start a completion at point using BACKEND." (interactive #f(compiled-function () #)) #) company-matlab-shell) company-begin-backend(company-matlab-shell) company-matlab-shell(interactive) funcall-interactively(company-matlab-shell interactive) ``` and the output in the console is: ``` >> emacsdocomplete('all') emacs_completions_output = java.lang.String[]: 'all' 'allchild' 'allElectrodes' 'allfeasible' 'allMuPADNotebooks' ``` which is the same output that I get by running M-x matlab-complete-symbol, if that helps to make sense of things. Thanks, Jonathan ___ Matlab-emacs-discuss mailing list Matlab-emacs-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss ___ Matlab-emacs-discuss mailing list Matlab-emacs-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss
Re: [Matlab-emacs-discuss] completion and goto-function in matlab-mode (Doom emacs)
Hi Eric, The `matlab-local-xref` backend is quite useful, thank you for taking the time to go through it. I did notice something in this function: (defun matlab-shell-xref-activate () "Function to activate xref backend. Add this function to `xref-backend-functions' for matlab shell to use xref to find function and variable definitions." (and (member major-mode '(matlab-mode matlab-shell-mode org-mode)) (matlab-shell-active-p) 'matlab-shell)) The test for major-mode is unnecessary since the xref backend is only loaded when matlab-mode is activated. Even if you decide to leave it in the reference to `org-mode' is completely superfluous. This is some debug code that I forgot to take out before I submitted the patch. (The same applies to the function `matlab-local-xref-activate'.) So we just need (defun matlab-shell-xref-activate () "Function to activate xref backend. Add this function to `xref-backend-functions' for matlab shell to use xref to find function and variable definitions." (and (matlab-shell-active-p) 'matlab-shell)) Karthik Eric Ludlam writes: > Hi Karthik, > > Thanks for the update and explanation. > > I finally had some time to sit with your code, try it out in a few > situations, and teach myself how xref works. I haven't had much > opportunity to learn all the new stuff in eieio that it uses, so that > was nice. > > I created matlab-xref.el on the shellcomplete branch which includes a > tweaked version of your code. > I included an xref engine that will do local symbol lookups for local > functions and the like. Combined, with the shell version, you can get > to most places quickly. > > I think this is a pretty good start. I've already found it changed the > way I do navigation. Very nice. > > Eric > > > On 12/23/20 5:04 AM, Karthik Chikmagalur wrote: >> Hi Eric, >> >>> I did look at the elisp backend which it advertised as the prime >>> example. That one is quite large compared to your patch. Do you >>> think the below would expand out to be much larger? I'm considering >>> if xref support would move into it's own file or not. >> The xref support for MATLAB in my patch is very short (relatively) >> because >> >> - I wrote it as a wrapper around `matlab-shell-which-fcn', which does >>the heavy lifing of finding the function in question. Matlab-shell >>already has support for jumping to definitions so I reused it. The >>downside is that matlab-shell needs to be running for xref support to >>work. This is not ideal, but the alternative is to write code to find >>function definitions from scratch. >> >> - Only jump to definition is implemented. Two other xref functions: >>`xref-backend-apropos' and `xref-find-references', are not implemented >>at all. I want to look into adding these, but I'm not sure right now >>how to go about it. >> >>> I also note that the elisp version doesn't use require for xref, and >>> your patch depends on the feature existing when the code loads. I >>> think it does so via: >>> >>> (declare-function xref-make "xref" (summary location)) >>> >>> Will that work here too? >> I think `declare-function' keeps the byte-compiler from complaining and >> doesn't do much else. This should help here, though, and checking if >> xref is loaded should be unnecessary. >> >> In summary, a slightly modified version of this patch can be included as >> preliminary xref support for matlab-mode. It can be its own file if it's >> expected to be expanded in the future with `xref-find-references' and >> other functionality, and prehaps written in a way as to not require >> matlab-shell to be running. >> >> Attached is a patch (as a separate file) with some minor modifications >> from last time. For it to be integrated into matlab-mode, one other >> piece of configuration is needed: >> >> (add-hook 'xref-backend-definitions #'matlab-shell-xref-activate) >> >> This needs to be added in the matlab-mode major mode definition in >> `define-derived-mode matlab-mode' in matlab.el. >> >> Karthik >> ___ Matlab-emacs-discuss mailing list Matlab-emacs-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss