Recent

Author Topic: Source code explorer - text search in file contents in a folder  (Read 955 times)

erol

  • New Member
  • *
  • Posts: 15
Source code explorer - text search in file contents in a folder
« on: February 14, 2025, 02:39:14 pm »
Hello friends,

This was helpful for me as a beginner. I hope you'll find it helpful too. You can search for a keyword in your source code folder or directory. Program will list the all files that has that keyword. Program is written in Lazarus (free pascal)  I shared the unit1 source code in my blog page, full source is attached to this message.

https://erolcum-blogspot-com.translate.goog/2025/02/lazarus-free-pascal-dosya-iceriginde.html?_x_tr_sl=tr&_x_tr_tl=en&_x_tr_hl=en&_x_tr_pto=wapp

https://www.youtube.com/watch?v=wpjl_qCjMLI
« Last Edit: February 17, 2025, 12:24:36 pm by erol »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10920
  • Debugger - SynEdit - and more
    • wiki
Re: Source code explorer - text search in file contents in a folder
« Reply #1 on: February 14, 2025, 03:36:03 pm »
Just to add a few more options, in Lazarus you have

- Find in Files
Which can search
 ~ in a folder, or a set of folders (separated by ; )
 ~ in the project
 ~ in the current file

- Find Identifier references
Which will find words but only if they are the same identifier. E.g. a searching "Count" for the property TList.Count will not find local vars that have the same name "Count".

- Identifier Dictionary (needs package "Cody" installed / needs some time to train itself)
Finds where a function is, and shows you the unit, or adds it to your project

- Package LazInstantSearch
Sort of a search in files, but faster / indexed

- and of course "Jump to declaration" to just find out where and how something is declared, if you already use it in your code.


Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10920
  • Debugger - SynEdit - and more
    • wiki
Re: Source code explorer - text search in file contents in a folder
« Reply #2 on: February 14, 2025, 03:42:43 pm »
What about a full download of your project/tool?

I don't know if it is just hard to find in the translation, or if it is missing, but all I found was the Pascal source of the "unit1"?
I did not see or find the unit1.lfm. Nor did I see the project1.lpr, and also not the project1.lpi.

You could provide them as a zip or make them available on any of the git hosting platforms, or other source sharing services.

erol

  • New Member
  • *
  • Posts: 15
Re: Source code explorer - text search in file contents in a folder
« Reply #3 on: February 14, 2025, 04:06:26 pm »
Hello Martin,
It is a simple but useful piece of code. And I wanted my blog reader (as a beginner) to prepare the form by himself or herself. There is a series of articles for beginners in my blog. You can be sure that source (unit1.pas) has no problem because of translation. Code block is not translated  ;) Source is attached in the first message. Thanks for the infos in your first message. Free pascal is really rich about libraries or possibilities
« Last Edit: February 17, 2025, 08:55:23 am by erol »

Dzandaa

  • Sr. Member
  • ****
  • Posts: 409
  • From C# to Lazarus
Re: Source code explorer - text search in file contents in a folder
« Reply #4 on: February 14, 2025, 04:12:50 pm »
Hi,

If you are looking for a real fast search for Windows even on all your disks, try this one:

Search everything

https://www.voidtools.com/

Just for Info.

@erol:
 you did a great job anyway :)



B->
« Last Edit: February 14, 2025, 04:14:44 pm by Dzandaa »
Regards,
Dzandaa

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10920
  • Debugger - SynEdit - and more
    • wiki
Re: Source code explorer - text search in file contents in a folder
« Reply #5 on: February 14, 2025, 05:12:55 pm »
You can be sure that source (unit1.pas) has no problem because of translation. Code block is not translated

Correct. The source block is 100% OK.

As for "full download" vs "tutorial - user build themself" => that is both ok.  A full download does not prevent a user to try for themself, if they want.

Btw, what may help other to understand the code, would be to name the button/edit/... E.g. Not "Edit3" but instead "FolderNameEdit". Then the user knows which edit is doing what.

And also as Dzandaa has said: Great work.

loaded

  • Hero Member
  • *****
  • Posts: 859
Re: Source code explorer - text search in file contents in a folder
« Reply #6 on: February 14, 2025, 05:36:51 pm »
Hi ,
I had done a similar package work to automatically add units to the project in the past. When you hover over a code you wrote in the Lazarus editor and press Left Click or Alt+Enter (I was inspired by Android Studio), it would list what it found in the fpc, lcl and component folders. It would add the library you wanted from among these to the uses section of the project. Or it would search on Google. If I can find it, I will add it here.

https://youtu.be/mIJbQjB_Gl8?si=ER4_NutSl51oUdBL

You can download it from this topic here.
https://forum.lazarus.freepascal.org/index.php/topic,58173.msg434285.html#msg434285
« Last Edit: February 16, 2025, 08:03:43 am by loaded »
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

d2010

  • Full Member
  • ***
  • Posts: 122
Re: Source code explorer - text search in file contents in a folder
« Reply #7 on: February 16, 2025, 03:12:43 pm »
Hello friends,
This was helpful for me as a beginner. I hope you'll find it helpful too. You can
I use fart.exe and his-source fart.cpp. You can translate his, source to Pascal.
If you got fart.pas, then you send to me his source?
If you got fart.pas, then you send to me his source?
Code: [Select]
cls
rename G:\vlaxcompil\Bin.w32\comcatc?.dll C:\vlaxcompil\Bin.w32\comcatcd.dll
fart.exe -r -i *.bat C:\vlaxcompil\  C:\vlaxcompil\
fart.exe -r -i *.pas,*.dof,*.dpr,*.rc,*.iss D:\vlaxcompil\ C:\vlaxcompil\
fart.exe -r -i *.iss comcatcd.dll comcatce.dll
fart.exe -r -i *.cmd ctab=D: ctab=E:
fart.exe -r -i *.cmd dtab=D: dtab=E:
fart.exe -r -i *.dof HostApplication=E:\Windows\   HostApplication=%SystemRoot%\Windows\
fart.exe -r -i *.dof H OutputDir=C:\vlaxcompil\bin.w32\   OutputDir=C:\vlaxcompil\bin.w32\
fart.exe -r -i *.rc C:\vlaxcompil\ C:\vlaxcompil\
This solution is not very good, solution, but that is other solution.
Already I used inside "Lazarus->MainMenu->Search in files"
For long-words ,"Lazarus->MainMenu->Search in files" is very good., but short words,"Lazarus->MainMenu->Search in files"  may can crash.
 %)
« Last Edit: February 16, 2025, 03:15:54 pm by d2010 »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10920
  • Debugger - SynEdit - and more
    • wiki
Re: Source code explorer - text search in file contents in a folder
« Reply #8 on: February 16, 2025, 04:12:49 pm »
but short words,"Lazarus->MainMenu->Search in files"  may can crash.

If that happens, then you should report a bug please. And please add, what actions must be done to make it crash.

What did you search, what did you click, what causes the crash?

erol

  • New Member
  • *
  • Posts: 15
Re: Source code explorer - text search in file contents in a folder
« Reply #9 on: February 16, 2025, 05:04:05 pm »
Hi ,
I had done a similar package work to automatically add units to the project in the past.

https://youtu.be/mIJbQjB_Gl8?si=ER4_NutSl51oUdBL

You can download it from this topic here.
https://forum.lazarus.freepascal.org/index.php/topic,58173.msg434285.html#msg434285

thank you I’ll check it

erol

  • New Member
  • *
  • Posts: 15
Re: Source code explorer - text search in file contents in a folder
« Reply #10 on: February 17, 2025, 12:59:59 pm »
Hi ,
I had done a similar package work to automatically add units to the project in the past. When you hover over a code you wrote in the Lazarus editor and press Left Click or Alt+Enter (I was inspired by Android Studio), it would list what it found in the fpc, lcl and component folders. It would add the library you wanted from among these to the uses section of the project. Or it would search on Google. If I can find it, I will add it here.

https://youtu.be/mIJbQjB_Gl8?si=ER4_NutSl51oUdBL

You can download it from this topic here.
https://forum.lazarus.freepascal.org/index.php/topic,58173.msg434285.html#msg434285

@loaded, sorry not working. When click to search, it does not search internal lazarus components folder
« Last Edit: February 17, 2025, 01:32:28 pm by erol »

loaded

  • Hero Member
  • *****
  • Posts: 859
Re: Source code explorer - text search in file contents in a folder
« Reply #11 on: February 17, 2025, 06:13:01 pm »
@loaded, sorry not working. When click to search, it does not search internal lazarus components folder
Hi Erol, Thank you for installing and trying the package.
I wrote this work about 3 years ago in Lazarus 2.0.10. The application found and searched for the relevant folders. The codes are in the "unit_sua.pas" file. Here, Lazarus detects these folders by reading the "environmentoptions.xml" file. Then it uses these folders in the search. I guess a lot of water has passed under the bridge. 😅 If you can review and update the codes here, the problem will be solved. I will review it when I have time and write the necessary corrections. Best regards.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

erol

  • New Member
  • *
  • Posts: 15
Re: Source code explorer - text search in file contents in a folder
« Reply #12 on: February 19, 2025, 09:29:37 am »
@loaded, sorry not working. When click to search, it does not search internal lazarus components folder
Hi Erol, Thank you for installing and trying the package.
I wrote this work about 3 years ago in Lazarus 2.0.10. The application found and searched for the relevant folders. The codes are in the "unit_sua.pas" file. Here, Lazarus detects these folders by reading the "environmentoptions.xml" file. Then it uses these folders in the search. I guess a lot of water has passed under the bridge. 😅 If you can review and update the codes here, the problem will be solved. I will review it when I have time and write the necessary corrections. Best regards.
As Martin said above, Cody also creates a solution for the ‘error: identifier not found’ problem. I was able to run your code and it works fine with Alt+Enter keys. As you said, the directory structure of Lazarus has changed in 3 years. You know the sentence : Even if nothing happened, something happened  :D The attached package works on Windows. It was enough to specify the paths to the lcl, components and source directories in unit_sua.pas (marked with comments). I can't write the code that will work both on windows and linux yet, but maybe you can. C:\Users\<user>\AppData\Local\lazarus\onlinepackagemanager\packages may be added to the following directories.
Code: Pascal  [Select][+][-]
  1. // Added 3 lines before Break;
  2. SetLength(result,length(Result)+1);result[high(result)]:='c:\lazarus\lcl\';
  3. SetLength(result,length(Result)+1);result[high(result)]:='c:\lazarus\components\';
  4. SetLength(result,length(Result)+1);result[high(result)]:='c:\lazarus\fpc\3.2.2\source\';
  5.  



« Last Edit: February 19, 2025, 10:17:54 am by erol »

loaded

  • Hero Member
  • *****
  • Posts: 859
Re: Source code explorer - text search in file contents in a folder
« Reply #13 on: February 20, 2025, 02:44:18 pm »
Of course it can be, but. I don't know if you've used it before, but there was an application called Google Desktop Search, and I noticed that it was extremely efficient in searches like this. I was thinking of doing something like this when I had time. But there is a saying, "The account at home does not match the market". I'm in this situation right now. 🤔

I also remembered another feature of the component and wanted to let you know, apart from the alt+enter shortcut, there is a feature to add content to the popup menu of a Lazarus editor. 👍
« Last Edit: February 20, 2025, 02:46:27 pm by loaded »
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

d2010

  • Full Member
  • ***
  • Posts: 122
Re: Source code explorer - text search in file contents in a folder
« Reply #14 on: February 23, 2025, 12:20:40 pm »
Hello friends,
This was helpful for me as a beginner. I hope you'll find it helpful too.

Please when you resize the windows, a, then alwayes you move "The Search-Button
on right on screen, not outside of MainFom.
Code: [Select]
Var pos1:array of integer;
Var clr:integer;
Begin  SetLength(pos1,512);
         for clr:=01 to 512 do pos1[clr]:=00;
End;
{--}
   
You save first position(eg. first 10postion each file, from file, not only filenames)
[code]
const maxposeacfile=10
Var PostiionInsideFile:array[0..10,0..0] of integer;
Begin setLength( PostiionInsideFile, how manyFile);

 

TinyPortal © 2005-2018