Sign in to follow this  
Followers 0
Imbuter2000

SciTE shortcut to jump to the beginning of a function

29 posts in this topic

Is there in SciTE a keyboard shortcut for jumping to the beginning of the function the cursor is in?

I feel many times the need of it.... having many and long functions...

Share this post


Link to post
Share on other sites



SciteJump should be able to help with that.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

As BrewManNH said, SciTE Jump. Hit Ctrl + J in SciTE if you're using SciTE4AutoIt3 and look in my signature for the latest version.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

The way I read the question is that the OP is somewhere working in the FUNC-ENDFUNC itself and want to jump to the first line of the FUNC.

Ctrl-J works out of the box when you have the full version of SciTE loaded, and jump from a Function reference to the FUNC Definition.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

The way I read the question is that the OP is somewhere working in the FUNC-ENDFUNC itself and want to jump to the first line of the FUNC.

Yes Jos correctly understood my different question: I would a shortcut that when my cursor is somewhere inside FUNC-ENDFUNC jumps to the FUNC line.

Ctrl+J doesn't do this and neither do SciTE jump :(

Share this post


Link to post
Share on other sites

Ctrl+J doesn't do this and neither do SciTE jump :(

Correct, as I stated, that jumps from a Func Refference to the FUNC definition.

There is no buildin way to jump to the top of the FUNC you are working in.

I am sure it is possible but can't see the general use of it to build this in via a LUA script option.

Jos :)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

How large a function is this? Maybe it would be better to have the function built with other function calls, to keep it from growing too large.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Correct, as I stated, that jumps from a Func Refference to the FUNC definition.

There is no buildin way to jump to the top of the FUNC you are working in.

I am sure it is possible but can't see the general use of it to build this in via a LUA script option.

Jos :)

I'ld like it mainly for two uses:

- when I want to add local or global variables at the beginning of the current function

- when I want to (fastly) read the function from the beginning of it for remind

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

This is a lua func that should be close to what you want. It uses Ctrl+u to jump up to FUNC and also uses Ctrl+Shift+J to Jump back.

Add this to sciteuser.properties:

# 35 Jump up to Func def
command.name.35.$(au3)=Jump up to Func begin
command.mode.35.$(au3)=subsystem:lua,savebefore:yes
command.shortcut.35.$(au3)=Ctrl+u
command.35.$(au3)=InvokeTool AutoItGotoDefinition.GobacktoDefinition

Add this to file AutoItGotoDefinition.lua

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- GobacktoDefinition()
--
-- Jumps up to a function definition.
--
-- Tool: AutoItGotoDefinition.GobacktoDefinition $(au3) savebefore:yes Ctrl+u Goto Definition
--------------------------------------------------------------------------------
function AutoItGotoDefinition:GobacktoDefinition()
    -- Get current pos
    local Pos_Carret = editor.CurrentPos
    -- get current text
    local text = editor:GetText()
    -- Force to lower case
    text = text:lower()
    local Next_Pos_Func = 0
    local Next_Pos_EndFunc = 0
    local Pos_Func = 0
    local Pos_EndFunc = 0
    -- Look for the Func definition above current line and find belonging EndFunc.
    repeat
        Pos_Func = Next_Pos_Func
        Pos_EndFunc = Next_Pos_EndFunc
        Next_Pos_Func = text:find("func .*%(", Pos_Func + 1)
        if Next_Pos_Func ~= nil then
           Next_Pos_EndFunc = text:find("endfunc", Next_Pos_Func + 1)
        end
    until Next_Pos_Func == nil or Next_Pos_Func > Pos_Carret
    --
    if Pos_Func == nil then Pos_Func = 0 end
    if Pos_EndFunc == nil then Pos_EndFunc = 0 end
    -- Check if we found a Func definition above the Carret and an EndFunc below the carret to ensure we are inside an Func.
    -- set up a marker and go to the function.
    if Pos_Func ~= 0 and Pos_Func < Pos_Carret and Pos_EndFunc > Pos_Carret then
        -- save current location
        if props['SciteLastJumpFromFile'] == nil or props['SciteLastJumpFromFile'] == "" then
            props['SciteLastJumpFromFile'] = string.gsub(props["FilePath"],"\\","\\\\") .. "|"
            props['SciteLastJumpFromPos'] = editor.CurrentPos .. "|"
        else
            props['SciteLastJumpFromFile'] = string.gsub(props["FilePath"],"\\","\\\\") .. "|" .. props['SciteLastJumpFromFile']
            props['SciteLastJumpFromPos'] = editor.CurrentPos .. "|" .. props['SciteLastJumpFromPos']
        end
        editor:EnsureVisible(editor:LineFromPosition(Pos_Func))
        editor:GotoLine(editor:LineFromPosition(Pos_Func))
    end
end    -- GobacktoDefinition()

Enjoy,

Jos :)

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

This is a lua func that should be close to what you want. It uses Ctrl+u to jump up to FUNC and also uses Ctrl+Shift+J to Jump back.

Add this to sciteuser.properties:

# 35 Jump up to Func def
command.name.35.$(au3)=Jump up to Func begin
command.mode.35.$(au3)=subsystem:lua,savebefore:yes
command.shortcut.35.$(au3)=Ctrl+u
command.35.$(au3)=InvokeTool AutoItGotoDefinition.GobacktoDefinition

Add this to file AutoItGotoDefinition.lua

--------------------------------------------------------------------------------
-- GobacktoDefinition()
--
-- Jumps up to a function definition.
--
-- Tool: AutoItGotoDefinition.GobacktoDefinition $(au3) savebefore:yes Ctrl+u Goto Definition
--------------------------------------------------------------------------------
function AutoItGotoDefinition:GobacktoDefinition()
    -- Get current pos
    local cpos = editor.CurrentPos
    -- get current text
    local text = editor:GetText()
    -- Force to lower case
    text = text:lower()
    local pos = 0
    local lpos = 0
    -- Look for the function definition above current line.
    repeat
        lpos = pos
        pos = text:find("func .*%(", pos + 1)
    until pos == nil or pos > cpos
    -- We found a function definition, set up a marker and go to the function.
    if lpos ~= nil and lpos ~= 0 and lpos < pos then
        -- save current location
        if props['SciteLastJumpFromFile'] == nil or props['SciteLastJumpFromFile'] == "" then
            props['SciteLastJumpFromFile'] = string.gsub(props["FilePath"],"","") .. "|"
            props['SciteLastJumpFromPos'] = editor.CurrentPos .. "|"
        else
            props['SciteLastJumpFromFile'] = string.gsub(props["FilePath"],"","") .. "|" .. props['SciteLastJumpFromFile']
            props['SciteLastJumpFromPos'] = editor.CurrentPos .. "|" .. props['SciteLastJumpFromPos']
        end
        editor:EnsureVisible(editor:LineFromPosition(lpos))
        editor:GotoLine(editor:LineFromPosition(lpos))
    end
end -- GobacktoDefinition()

Enjoy,

Jos :)

WOW! :)

There's only a problem: after I added and saved those pieces of codes to the two files, I restarted SciTE and tried the keyboard shortcuts and nothing happened :(

Share this post


Link to post
Share on other sites

WOW! :)

There's only a problem: after I added and saved those pieces of codes to the two files, I restarted SciTE and tried the keyboard shortcuts and nothing happened :(

Works for me, tried in on a clean install of SciTE4AutoIt3.

It doesn't do anything when there is no FUNC above the caret, else it will go to the first FUNC up.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I tried it, perhaps I did something wrong but I get this error output...

...ram FilesAutoIt3SciTELuaAutoItGotoDefinition.lua:328: attempt to compare number with nil

>Lua: error occurred while processing command

EDIT:

Line is in the new definition...

if lpos ~= nil and lpos ~= 0 and lpos < pos then

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

if lpos ~= nil and lpos ~= 0 and lpos < pos then

Yeap ... that statement is wrong and should be:

if lpos ~= nil and lpos ~= 0 and lpos < cpos then

Let me know if that solves it.

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Works for me, tried in on a clean install of SciTE4AutoIt3.

It doesn't do anything when there is no FUNC above the caret, else it will go to the first FUNC up.

ah, damn, I tried it while inside a function of your file AutoItGotoDefinition.lua without notifing that it's not an AutoIT code! the function code there starts with "function" instead than "func".

On AutoIT code it works! :))) thanks!!!

Edited by Imbuter2000

Share this post


Link to post
Share on other sites

Sweet,

I will leave the code in the production LUA file but probably won't add the shortcut to au3.properties unless there is a greater demand for it.

Jos :)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Update about my main uses of these shortcuts:

- when I want to add local or global variables at the beginning of the current function

- when I want to check or modify the parameters passed to the current function

- when I want to read again the function from the beginning of it for remind

Share this post


Link to post
Share on other sites

Imbuter2000,

Just an aside on that list - declaring Global variables within a function should be avoided. Although the code will still run, AU3Check will give you a warning as it is considered bad coding practice - Global variables should really be declared at the top of the script. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

There's a little bug/lack in the ctrl+U function:

when you use it while your cursor is out of any function it jumps to the first previous "func" (if any), despite the fact that your cursor is not inside it.

I know that it's not usually recommended to have (non function) code after a function but I would expect it to jump to the absolute beginning of the code in that case. Jumping to the first previous "func" made my (wrongly) believe that cursor was inside that function...

Edited by Imbuter2000

Share this post


Link to post
Share on other sites

Imbuter2000,

Perhaps reorder your script so that there is no code after the final function. You are quite correct that it is not recommended - so why do it? ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0