NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
How to start PHPEd from command line to let it go to line?


Joined: 06 Jul 2019
Posts: 1
Reply with quote
Hi Editor,
Here I have a requirement, which is, I need to integrate PHPEd with some of other tools. When I'm editing some codes in other editors, I need to open the file in PHPEd, and let PHPEd go to certain line of code(or even better, certain char in the line). Just don't know whether there's already such options in PHPEd command line arguments? I've tried something like 'phped.exe -n xxx myfile.php', but it does not work. If there's no such option, I suggest to add it in the next edition. Even better, I hope to be able to go to certern char in the line, or even select a block of text with certain length(with the cursor at the end of the selection block).
Thanks!
Dong
View user's profileFind all posts by yangdongSend private message


Joined: 27 Mar 2023
Posts: 48
Reply with quote
Hi!

I had the very same problem, and so I wrote a simple AutoIt script which can be compiled under Windows to do exactly this:

edit.exe path/to/script.php#33

will open the file in PhpED and go to line 33

If run with no prameters will register the executable as he handler for the protocol, so that clicking on a link q4://path/to/script.php#33 will run the very same command at written here

Here the script:

#region - Compiler directives section
#Compiler_OutFile="D:WebServedit.exe"
#endregion
$urlhandler = "D:WebServedit.exe" ;this should match Compiler_OutFile above

;config
$baseprotocol="q4"
$protocoldescription="URL: Q4 cms source editing protocol"

;editor to use
;$editor="C:Program FilesGeanybingeany.exe"
$editor="C:Program FilesNuSpherePhpEDphped.exe"
;$editor="C:Program Files (x86)PSPad editorPSPad.exe"

;init
$file=""
$linenumber=""

;processing command line parameters
if $CmdLine[0]>=1 then
;if we have at least one parameter

;find the source file pointed
$filesplit=StringSplit($CmdLine[1],"#")
$file = $filesplit[1]
$file = StringReplace($file,$baseprotocol & "://","")
;$file = StringReplace($file,$baseprotocol & ":\","")
$file = StringReplace($file,"/","")
;MsgBox(0, "Source file", $file)

;if the first parameter contained a #xxx use that as the line number to go to
if $filesplit[0]>1 then
$linenumber = $filesplit[2]
EndIf
;MsgBox(0, "Line number", $linenumber)

;prepare the command line to execute
$execute = '"' & $editor & '"' & " " & '"' & $file & '"'
if ($linenumber<>"") then
if (StringInStr($editor,"geany.exe")) then
;geany accepts :linenumber parameter to go to specific line in file
$execute = $execute & ":" & $linenumber
EndIf
endif
;MsgBox(0, "Execute",$execute)

;run the editor
Run($execute,"",@SW_MAXIMIZE)

;phped does not accept a command line to get to a specific line
if ($linenumber<>"") then
If (StringInStr($editor,"phped.exe")) then
;so we send Ctrl+G, line number, Enter keys to make it go to that line
if WinActivate("PhpED") then
Send("^g")
Send($linenumber & "{ENTER}")
endif
endif
endif
Else
;if no parameter has been sent, then registers the compiled version of this script as handler for this protocol
RegWrite("HKCR" & $baseprotocol, "", "REG_SZ", $protocoldescription)
RegWrite("HKCR" & $baseprotocol, "URL Protocol", "REG_SZ", '')
RegWrite("HKCR" & $baseprotocol & "DefaultIcon", "", "REG_SZ", '"' & $editor & '"')
RegWrite("HKCR" & $baseprotocol & "shellopencommand", "", "REG_SZ", '"' & $urlhandler & '" "%1"')
MsgBox(0, "RegWrite", "Registry Entries Added." & @LF)
endif


Hope this is useful!
View user's profileFind all posts by ShoresOfNowhereSend private message


Joined: 14 Jun 2006
Posts: 3
Reply with quote
Cool script, but you can also directly goto line using this parameter.

peped.exe "file.php" --line=30

As described in this post;
https://forum.nusphere.com/improvement-for-opening-files-from-commandline-t4722.html
View user's profileFind all posts by abosboomSend private message


Joined: 27 Mar 2023
Posts: 48
Reply with quote
Nice info, thanks!

But someone does know where a FULL LIST of phped command line options can be found?

The manual inside PhpED does not contain it, and I cannot manage to find it anywhere else...
View user's profileFind all posts by ShoresOfNowhereSend private message
How to start PHPEd from command line to let it go to line?
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic