VSCode Extension - Rename Symbols - visual-studio-code

I have seen this link:
VsCode Extension: Rename Symbols
but it doesn't solve my questions.
My problem is that I only have a file as context, not some kind of cursor position. I would like to find the position of a certain symbolname in it (in my case, object name in al language - but that's besides the point).
I know the first match of a certain text will be the symbol ...
Thing is, I need code to be able to rename the symbol, and I have two problems with the code that I found in the link above:
first, as said, I don't know how I can get to the position of a certain string. I can get to the index, but not the position.
second, the last line of that example doesn't compile, since the "edit" variable is of type {}, and isn't allowed as a parameter in the ApplyEdit function.

The built-in rename ui is designed for renaming a symbol as a specific location.
If you want to rename a symbol in a file without using the current position, you can build your own flow using vscode.showInputBox to prompt the user for the new name and WorkspaceEdit + applyEdit to perform the rename itself

Related

Copy name of object in variable explorer

I frequently find myself examining deeply nested data in the variable explorer, e.g.:
objectName.structArray1(5).structArray2(3).structArray3(7).doubleArray(4)
In order to be descriptive, the variable names are often long. I often want to use some of the data I'm looking at in Matlab expression, composed at the command line. So I end up typing the lengthy series of variable names and indexes. Autocompletion helps, but not much, especially since my variable names share many substrings.
It would be a lifesaver if I could copy into the clipboard the entire expression corresponding to the data being examined in the variable viewer. I haven't yet found a way to do this (the most obvious way being to right-click the tab for the data being examined). So I'm not sure if this functionality exists. Can anyone confirm or deny (hopefully the former) whether this functionality exists? If it does, how is it done?
As an example, suppose you had a class file myClass.m in the current working directory:
% myClass.m
%----------
classdef myClass
properties
structArray1
end % properties
end % class
Now suppose you issued the following commands:
objectName = myClass
objectName.structArray1(5).structArray2(3).structArray3(7).doubleArray(1:3)=rand(1,3)
openvar('objectName.structArray1(5).structArray2(3).structArray3(7).doubleArray')
You are now examining a slew of data within a deeply nested data structure. Normally, the data would have been the result of computation other than the rand statement above, and I would have browsed to it manually rather than using the openvar statement above. So I would not normally have readily available the text for the expression
objectName.structArray1(5).structArray2(3).structArray3(7).doubleArray
I have to manually type it in at the command line if I want to use it in a Matlab expression for further computation. It'd be so great if I could somehow point to the tab for that data in the variable explorer and somehow have the expression for the data copied to the clipboard. That way, I can paste it to the command line.
AFTERNOTE:
If there's no way to do this, then as an alternative to manually typing in the whole expression above, is there a way to access the corresponding data object (or a copy thereof) programmatically through the variable explorer window object? This assumes, of course, that the variable explorer is itself a data object as well, through which properties can be accessed. If so, maybe it has a property (perhaps deeply nested) that represents the expression for data in the tab that currently has the focus. If so, I can write a function to retrieve the corresponding data object.
I found that if I undock a tab from the Variables editor, I can select the variable name by double-clicking the variable name in the tab.
Sorry for the ambiguity in wording, but "tab" use to mean the protrusion in the data sheet for displaying the name of the data sheet. Nowadays, "tab" means the whole data sheet. In the first sentence above, I mean the protrusion, which unfortunately doesn't have a distinct name these days (at least none of which I'm aware).
After copying and pasting the variable name from the protrusion, the tab can be docked, which seems to put it back into its original place.

MATLAB GUIDE GUI errors following function name change

I have renamed a .fig and associated .m file generated by MATLAB's GUIDE. Having done this, I receive a long list of error messages including the following (just a sample of them shown below):
Undefined function or variable 'my_gui'.
Error in #(hObject,eventdata)my_gui('edit34_CreateFcn',hObject,eventdata,guidata(hObject))
Undefined function or variable 'my_gui'.
Error in #(hObject,eventdata)my_gui('edit33_CreateFcn',hObject,eventdata,guidata(hObject))
Undefined function or variable 'my_gui'.
Error in #(hObject,eventdata)my_gui('edit32_CreateFcn',hObject,eventdata,guidata(hObject))
These errors all seem to relate to individual items on my GUI, such as buttons, text boxes etc.
The function and .fig file used to be called my_gui.m and my_gui.fig. However, I have sinced changed the name to my_new_gui.m and my_new_gui.fig (I've simplified the actual names for the purposes of this question).
So, the obvious solution is to go into the .m file and replace all instances of my_gui with my_new_gui. However, I've done this, and the same error message appears. I have no idea where MATLAB is the reading text my_gui from, since it doesn't exist in any of my code... Any help would be appreciated!
Edit I've discovered that these old references are written in the callbacks for each item on the GUI, which I can change by opening the Property Inspector for each individual item. However, I have a lot of items. If anyone can offer a solution to quickly edit these using a text editor, rather than clicking each individual one, I'd appreciate it!
Renaming MATLAB GUI should be done using Save As... rather than manually changing the file names. Change the file names back to the original names and change the name using Save As... option in GUIDE. This should automatically rename everything.

MATLAB IDE: F1-key and doc function displays help for the wrong function

I've been working for some time on a MATLAB function to retrieve file names. The function is called getFileName. My problem is that when I try to display help for this function by pressing the F1 key while cursor is on the function name, I instead, get the help for the built in function matlab.io.hdf4.sd.getFilename. I get the same if I write doc getFileName in my command window. Only if I type helpwin getFileName do I get the correct documentation displayed!
This doesn't make sense to me since MATLAB is case sensitive and thereby getFileName is different from getFilename. Furthermore, when I type which getFileName (or for some strange reason, if I type which getFilename), I get the path to my function and not to the built-in function matlab.io.hdf4.sd.getFilename.
So my question is: is it possible to make sure that the function you get documentation for (by pressing the F1 key) is the same function that you run if you type the name of that function?
Matlab isn't actually case sensitive for the help files. In the terminal you can type
doc PLOT
and it will still pop up the documentation for the proper plot function.
I don't know where these files are stored on PC, as I use a Mac, but in the Matlab directory if you search for an uncommon file name (like plotyy) you will see the source file, but you'll also find an html file that doc uses. If you write an html file for the new file it should bring up the right info for the documentation center.
Matlab used to just copy the commented text at the beginning of the file into the documentation center in older versions of matlab, but now it uses html files stored on your drive. I don't know if this will definitely fix your problem as I haven't written an html file for an "almost overloaded" function.
Also, about the weird 'which' thing, I'm pretty sure Matlab first searches the first entry on your path list for a close match, and the current directory is on the top of the list. If you type 'path' into the console it will output all the search paths, and the top ones are searched first.
I apologize for masquerading as if this is an 'Answer' but I don't have enough reputation points to add this as a comment.

find function in MATLAB code

I would need to find all the places in my code (several M files in a folder) where I used a particular function (unique in this case).
Do you know if it is possible?
In Matlab, there is the command "Find Files" - in the "Edit" menu, or on the "Home" and "Editor" ribbon - that allows you to find files containing specific text, either in a folder or on the entire Matlab path:
Use the "find in files" function in Notepad++
If you want to check what functions you're using, depfun allows you to do so, although it might be overkill if you only want to check for a single known function.
For example (checking functions called directly by a function only):
[list builtins] = depfun(fun, '-toponly');
"which" seems to do it.
Take a look at this: http://www.mathworks.co.uk/help/matlab/ref/which.html (1st example)
Otherwise, notepad++ allows you to search (and replace) multiple files for a text string, here's a simple tutorial:
http://www.makeuseof.com/tag/how-to-find-and-replace-words-in-multiple-files/

How can I make a singleton bookmark in my org file?

I have an org-mode task list that I keep in version control. I would like to press a key and turn the current position into a bookmark target that I will be able to access anywhere I have the list checked out, regardless of other changes that have been made to the document. This is why (bookmark-set) will not work.
Additionally I would like to ensure that this target only occurs once in the file. If I put the target at a different position I want the original target to go away.
Essentially, I want to combine features of Emacs bookmarks (the singleton aspect), and org-mode links (more robust persistence). What's the best way to do this?
You want to read up about Markers:
M-: (info "(elisp) Markers") RET
This feature is what allows the mark ring to retain its relative locations regardless of buffer changes, for example.
If you want the marker to be stored within the file itself, then you might want to include it as a local variable in the file itself, and use before-save-hook to update that to the current value.
The local variable may need to be an integer, in which case you would need to translate it on loading and saving.
(This is a little speculative, but I suspect it will do the trick.)
The best solution I've been able to come up with is to use the text <<<BOOKMARK>>>, and to search for it when necessary. At some point I might write some functions that place this bookmark and delete it from elsewhere.