CURRENT_WORD not selecting the proper text when used in column mode
-
Is there something similar to CURRENT_WORD that will only select the highlighted text in column mode (holding down ALT while selecting text in multiple rows)?
-
Interesting idea. There isn’t currently, that I know of.
But since the purpose of
$(CURRENT_WORD)
and similar is to pass text to a command-line argument of an external command, I am wondering how you would expect the rows would be delineated (since column-selections use newline characters internally for separating each row of the selection) – and newlines and command-line arguments don’t always work well together. -
@PeterJones I can strip out the newline characters in the receiving application so that’s not that much of a problem. The problem is all the unknown data that I didn’t want is included in CURRENT_WORD. BTW, my quick workaround is to copy the column selected data, paste that to a new file, select all the data in the new file and then pass that to my application, along with the newlines. It’s a bit clumsy but it seems to work, My new problem is from a macro I can’t seem to launch a user defined run command so now i’m doing one key sequence to collect only the column data and another key sequence to execute the receiving application.
-
@Howie-Thurer said in CURRENT_WORD not selecting the proper text when used in column mode:
I can strip out the newline characters in the receiving application so that’s not that much of a problem
It’s not the receiving application that I was worried about. It’s how the command line interface is going to handle newlines in a command-line argument. Doing something from the “Run” menu is essentially equivalent to doing something from the Windows Win+R Run dialog or from the cmd.exe window, and it’s rather difficult to get newlines in command-line arguments there. (Notepad++ essentially takes the text you type in the RUN box, runs the $(…) replacements, concatenates it into a single string, and then asks the OS to run that string… it’s that “asks the OS to run that string” with a newline in the string that’s the problem, IMO.
My new problem is from a macro I can’t seem to launch a user defined run command so now i’m doing one key sequence to collect only the column data and another key sequence to execute the receiving application.
If you want to do complicated manipulation, but know a little Python programming, you could use the PythonScript plugin, and write a script which takes the active selection (which could be a column or regular selection) and then transforms it somehow (maybe use some other character other than CR/LF for the “line separator”) and then passes it into your receiving application – that might overcome the difficulties with the newlines from the selection. Since you can bind a pythonscript to a single keystroke, you could make the script do everything that the macro did plus pass it to the app like the run command did, and thus going back to one keystroke.
-
@PeterJones
Thank you for your help. It passing the newlines to the application seems to work OK, at least in Win10.I’ve never written a Python script before but I guess I can look into that.
Is it possible to execute a Run command from a Macro. I tried using the assigned key shortcut but it didn’t work. For now I need to execute one key sequence to execute the Macro which strips out the unwanted characters, and keeps the desired data and then another key sequence to execute the run which passes the CURRENT_WORD to my application where the newlines are removed and the data is processed. It would be better in a single key sequence could do both.
-
@Howie-Thurer said in CURRENT_WORD not selecting the proper text when used in column mode:
Is it possible to execute a Run command from a Macro
Not really. Macros can only run permanent menu entries which have their internal command-ID compiled into the program (and can actually only run only a subset of those). Run menu entries are stored in a config file, and are added to the Run menu dynamically (without a permanent command-ID compiled into the program), so the Macro interface cannot access them.
That’s why I suggested the alternative of using the PythonScript plugion, because that plugin is able to do everything you can do in a macro (and more) and everything you can do in a Run command (and more), and combine the two together.
-
@PeterJones
Thanks. I installed Python and am starting to look into how to use it.
Do you have any web sites or tutorials you can recommend? -
@Howie-Thurer said in CURRENT_WORD not selecting the proper text when used in column mode:
I installed Python and am starting to look into how to use it.
Did you install Python? Or did you install the PythonScript plugin? They are two different things. Just installing Python will not help, because it doesn’t come with anything Notepad++ specific to help you. The PythonScript plugin for Notepad++ (going to Plugins > Plugins Admin and installing PythonScript) will install an environment inside of Notepad++ that can run python code to automate Notepad++, and you don’t need to install a standalone Python for it to work.
But since you need to know python syntax to use PythonScript: I don’t have any recommended Python tutorials, as when I first got PythonScript, I knew enough other coding languages that seeing the PythonScript documentation and examples in this forum and searching the Python 2.7 documentation was enough for me. Googling for “Python 2 tutorial” might find you something. (Make sure it’s Python 2 specific, because for now, the copy of Python that comes with PythonScript is v2.7, despite the fact that the Python community at large is at 3.XX and highly discourages continuing to use Python 2.7)
-
@PeterJones
I installed Python.
I also installed NppExec plugin and Python Script Plugin.
Thanks. The NppExec showed how to run Python code and to print “Hello World”
I think I need to focus on the Python Script Plugin to accomplish what I’m trying to do.
Again, thank you, appreciate your advice. -
@Howie-Thurer said in CURRENT_WORD not selecting the proper text when used in column mode:
I think I need to focus on the Python Script Plugin to accomplish what I’m trying to do.
Yes.
It is OK that you have regular Python now, and the NppExec plugin. Both are “good to haves”. But they don’t help for what you are trying to do. NppExec perhaps could be of some help (I don’t know it that well), but with PythonScript you are definitely now on the fast track.
As a kickstarter for one of the things you need to do, you probably want to make sure you have a selection when you run your (future) script:
if not editor.getSelectionEmpty():
If you demand a column-block selection, then verify that with:
if editor.getSelectionMode() == SELECTIONMODE.RECTANGLE:
You probably want to retrieve the selected text:
text_of_col_block= editor.getSelText()
If you want/need, get the column block into a list of the text on each individual line:
sel_text_on_each_line_list = text_of_col_block.splitlines()
…maybe enough of a kickstarter for now…
But here’s another one for the second part of what you’re doing, IF you want to keep the “macro” approach; here’s a valid PythonScript syntax:
notepad.runMenuCommand('Macro', 'Your Macro Name')