AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Open Function Declaration (Notepad++)

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Xander



Joined: 23 Sep 2007
Posts: 142

PostPosted: Thu Nov 01, 2007 7:27 pm    Post subject: Open Function Declaration (Notepad++) Reply with quote

Here is a quick and dirty "open declaration" script. Within Notepad++, upon pressing Ctrl + D, the script will obtain the function at the current caret position then proceed to find the declaration of that function within the script and all included scripts. If found, it will open that script in Notepad++ and go to the line number of the function declaration.

Some limitations:
#Include must always use the working directory of the parent script
will only find functions that begin on a new line with no tabs or spaces and also have the { NOT start on the next line.

Code:
#SingleInstance Force
#NoEnv
SendMode Input

return

#IfWinActive ahk_class Notepad++
^d::
   OpenDeclaration()
   return
   
OpenDeclaration() {
   clip := ClipboardAll
   Send, ^{Right}^+{Left}^c
   function := Clipboard
   Clipboard := clip
   regex = ^%function%\([\w\s\,\=\"]*\)\s*{
   WinGetTitle, title
   files = 1
   files1 := SubStr(title, InStr(title, " - ") + 3)
   include = ^\#Include\s+([\w\s\.\\/]+)
   Loop {
      file := files%A_Index%
      StringGetPos, index, file, \, R
      dir := SubStr(file, 1, index)
      Loop, Read, %file%
      {
         if RegExMatch(A_LoopReadLine, regex) {
            OpenFile(file, A_Index)
            return
         }
         if RegExMatch(A_LoopReadLine, include, match) {
            files++
            files%files% = %dir%\%match1%
         }
      }
      if (A_Index >= files)
         break
   }
}

OpenFile(file, index) {
   RunWait, %A_ProgramFiles%\Notepad++\notepad++.exe "%file%"
   Send, ^g
   Sleep, 20
   Send, %index%{Enter}
}
Back to top
View user's profile Send private message
Xander



Joined: 23 Sep 2007
Posts: 142

PostPosted: Sun Nov 04, 2007 4:42 am    Post subject: Reply with quote

Added a little more sophistication but it is still only for Notepad++

Ctrl+D to go to the function declaration of the function at the current caret position.

Ctrl+P to list as a tooltip all the parameters of the function/command at the current caret position. Will search for functions in the script / included files as well as internal functions/commands. The function/command list compiled by dieom (I believe) is used.

Download:
http://www.autohotkey.net/~Xander/EditorHotkeys.zip

Example of showing the parameters of a user defined function:
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2526
Location: Australia, Qld

PostPosted: Sun Nov 04, 2007 6:31 am    Post subject: Reply with quote

Xander wrote:
The function/command list compiled by dieom (I believe) is used.
That appears to be a subset of the function/command list in AutoHotkey\Extras\Editors\Notepad++\AHK Autohotkey.api (part of the AHK install.) As I recall, dieom posted the list with no reference to its origin.
Back to top
View user's profile Send private message
Xander



Joined: 23 Sep 2007
Posts: 142

PostPosted: Sun Nov 04, 2007 11:47 pm    Post subject: Reply with quote

lexikos wrote:
Xander wrote:
The function/command list compiled by dieom (I believe) is used.
That appears to be a subset of the function/command list in AutoHotkey\Extras\Editors\Notepad++\AHK Autohotkey.api (part of the AHK install.) As I recall, dieom posted the list with no reference to its origin.
Yes, I got it from dieom's post in the ISense thread. Thanks for clarifying the origin.
Back to top
View user's profile Send private message
urlwolf



Joined: 16 Mar 2006
Posts: 100

PostPosted: Tue Jan 01, 2008 4:48 pm    Post subject: Reply with quote

I just tried this, and it does get the args for functions in the list, but it doesn't 'teleport' to the user function definitions.

Also, is there any reason why this is Notepad++ only?

Thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group