question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

-r command line option does not work in one instance mode & cudatext opened

See original GitHub issue

When I have "ui_one_instance": true in user.json, opened CudaText with another file and call cudatext -r anotherfile, new file is opened as read-write.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
Alexey-Tcommented, Jan 28, 2020

Just added (win32, did not test linux) -z=, -e=, -nh. the same easy way.

1reaction
dinkumoilcommented, Jan 20, 2020

@Alexey-T

I’m still too busy in my job to be able to fix that issue by myself but I did a code analysis to give you some hints for fixing it.

BTW: I would classify this issue not as an enhancement but as a bug instead. I was able to figure out that in single-instance-mode the whole command line parsing is reduced to file names, options are ignored as a whole, see below.

Analysis Results

File FormMain.pas contains the following code block (in procedure TfmMain.FormCreate at lines 1840 to 1850):

  {$ifdef windows}
  if IsSetToOneInstance then
    with TInstanceManage.GetInstance do
      case Status of
        isFirst:
          begin
            SetFormHandleForActivate(Self.Handle);
            OnSecondInstanceSentData := @SecondInstance;
          end;
      end;
  {$endif}

In single-instance-mode, after executing line 1847 the main/visible Cud instance is ready to receive data (i.e. command lines sent from subsequently started instances). When data is received, procedure TfmMain.SecondInstance is called (located in file FormMain.pas at line 1720).

The problem is, that TfmMain.SecondInstance checks every command line parameter if it is an existing file and opens it. Thus command line options like -r or even -n are skipped.

To solve the issue, procedure TfmMain.SecondInstance should call the same function that is used for parsing command line arguments. This would be procedure TfmMain.DoOps_LoadCommandLineOptions (located in file formmain_commandline.inc at line 10).

But currently TfmMain.DoOps_LoadCommandLineOptions is called from procedure TfmMain.DoOps_OnCreate (located in file FormMain.pas at line 2038) which in turn is called from TfmMain.OnCreate in line 2031. Furthermore, TfmMain.DoOps_LoadCommandLineOptions operates directly on the ParamStrUTF8 array but it should operate on the command line arguments sent from the subsequently started Cud instance in this case.

That means there has to be implemented some code that stores in single-instance-mode the whole command line of the first started Cud instance and in multi-instance-mode the whole command line of every Cud instance to an array. The same should happen in single-instance-mode in procedure TfmMain.SecondInstance with the command line data sent from a subsequently started Cud instance. Procedure TfmMain.DoOps_LoadCommandLineOptions should operate on that array.

Since procedure TfmMain.DoOps_LoadCommandLineOptions only parses command line options and doesn’t load the provided file(s), there already has to be a piece of code that does that but I haven’t found it. This part of code has to use the array mentioned above as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CudaText - Free Pascal wiki
-r - Open files from command-line in read-only mode. ... single-instance mode, so that program with one "group" will not interfere and find...
Read more >
CudaText/history.txt at master · Alexey-T/CudaText - GitHub
fix: macOS: "Open with / CudaText" did not work from Finder ... + add: command line parameter '-p' supports 'single instance' mode (thanks...
Read more >
Change-log - CudaText
AsString] * hotkeys part in Options dlg: now read-only, cannot change hotkeys there * SynPlugins.ini: not used last 2 items for command plugins:...
Read more >
CudaText 1.96 vs other Linux editors on huge lines - Reddit
Opening a large file in Vim is no problem usually. If you can give me a test sample I'll gladly try.
Read more >
Script runs from R, but not via command line - Stack Overflow
Loading required package: RODBC Error in sqlQuery(channelMflib, the.SQL) : first argument is not an open RODBC channel Calls: get.all.areas -> oceans.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found