5

I'm using Mate 1.2.0 in Linux Mint 13. The two text editors i use are Gedit and Geany (v0.25): i use Geany for all my coding as i prefer the syntax highlighting and some other interface features.

One thing that bugs me though is this behaviour:

  • open a file in Geany in workspace 1
  • go to workspace 2
  • double click a file to open it (in Geany)
  • the desktop switches to workspace 1 again and opens the file in Geany.

When i do this in Gedit, it opens a new instance of Gedit in that workspace, which suits my style of working perfectly, where i have different projects open in each workspace.

I can start another instance of Geany from the programs menu, and move one into the other workspace, but it doesn't change the behaviour: I then see this:

  • open a file in Geany in workspace 1
  • go to workspace 2
  • start a new instance of Geany from the program menu (so i now have one per workspace)
  • double click a file to open it (in Geany)
  • the desktop switches to workspace 1 again and opens the file in the first instance of Geany.

So it's like it always opens a file in the "primary" Geany, and switches to whatever workspace that happens to be in.

Is there a way i can change this behaviour? I'd like it to be like so:

  • On opening a file: is there a Geany running in this workspace?
    • yes: open the file in that Geany
    • no: open a new Geany in this workspace and open the file in that.

I can't see an option relating to this in the settings. Any advice appreciated! thanks

  • Hi Max - Have you solved your problem? I'd like to switch from gedit to geany, and that behaviour slow things down. Tx. – Olivier Delrieu Aug 9 '16 at 22:54
  • @OlivierDelrieu no, I never did. I didn't really try any more after asking. I just saw your answer, I will try that. – Max Williams Sep 20 '16 at 7:23
  • related: github.com/geany/geany/issues/1025 – lesmana Mar 29 '17 at 8:50
4

Use this batch to open Geany. This will open a separate socket specific to each workspace.

For example, in Thunar, use 'open with other application' and point to this batch file.

#!/bin/sh

socket=`xprop -root _NET_CURRENT_DESKTOP`
socket=${socket##* }

if [ "$socket" ]
then
    if [ "$DISPLAY" ]
    then
        socket="${DISPLAY%.*}-$socket"
        socket=${socket#*:}
    else
        socket="NODISPLAY-$socket"
    fi
    exec geany --socket-file "/tmp/geany_socket_$socket" "$@"
else
    exec geany "$@"
fi
  • Thanks. If I'm reading this right, then it won't work from a simple double click, but I at least can right-click and open in the current workspace geany? – Max Williams Sep 20 '16 at 7:25
  • yes, right-click - but, if you make this batch your default application (tick box in 'open with' window) it will also work with double clicks. Could also work in a terminal, if you put this batch in your path. Like you, I recently had to move from gedit to geany, and this batch works great. – Olivier Delrieu Sep 20 '16 at 15:21
  • ahhh i see. Yes that works great - thanks! – Max Williams Sep 20 '16 at 15:30
  • Btw, as a follow up, I've been using this for over a year now and there's been no problems at all. The only setup was initially telling lots of different file types to open with wgeany (a shortcut to the above) instead of geany. – Max Williams Nov 17 '17 at 13:24
  • Glad I could help. – Olivier Delrieu Nov 18 '17 at 16:49
2

Go to the terminal and type geany -h it will show you all the options availible. Among them -i, --new-instance Don't open files in a running instance, force opening a new instance is exactly what you need.

HOW-TO

  1. Find that thing you are clicking.

  2. Open it in any text editor, or find a way of changing the command it is executing. (might be tricky if it's a launcher in the tray, for example).

  3. Change the command from something like geany -some_options to geany -some_options -i

--

done.

  • Thanks @Ufos but i don't think this is what i'm looking for: this is the same as doing "start a new instance of Geany from the program menu (so i now have one per workspace)" in my second list of actions above. I can do this in my second workspace to open a file in a new instance of geany, but when i then double-click on a file, it switches me back to the orginal geany in workspace 1. I really need some behaviour which "knows" which workspace it's in, and uses the geany for this workspace, which gedit seems to do. – Max Williams Jan 8 '16 at 15:22
  • Yeah. Apparently Geany has something like "the main instance" because it opens any file in it even if you open two instances through terminal using -i. So, I opened two of them using geany -i and then geany filename (or the thunar "open with" option) creates another instance where this file and any consequent will be opened... Weird. I guess, the only solution, which you probably already know is to open files from the instance you want them to be in. Anyway, sorry for the wrong answer. Hopefully, it helps someone else. – Ufos Jan 13 '16 at 0:18
1

This became too long for a comment so I'm posting it as an answer instead. I had trouble getting Olivier's answer to work so I thought I would include more detailed instructions on his answer in case others have trouble too (all credit goes to him, upvote him instead of/as well as mine).

Create a batch file containing

#!/bin/sh

socket=`xprop -root _NET_CURRENT_DESKTOP`
socket=${socket##* }

if [ "$socket" ]
then
    if [ "$DISPLAY" ]
    then
        socket="${DISPLAY%.*}-$socket"
        socket=${socket#*:}
    else
        socket="NODISPLAY-$socket"
    fi
    exec geany --socket-file "/tmp/geany_socket_$socket" "$@"
else
    exec geany "$@"
fi

Put the batch file in a directory included in PATH (see https://stackoverflow.com/questions/14650070/how-to-execute-bash-script-from-any-location). I assume you name the batch file wgeany otherwise replace that in the following instructions with whatever you named it.

Now we will want to set this as our default program to open text files. Unfortunately, it is not on the list and at least in my version you do not get to make a custom pick unfortunately.

We can solve this by going to ~/.local/share/applications or /usr/share/applications (if one doesn't exist/doesn't work/you don't have permission for it try the other) and create a text file named wgeany.desktop containing:

[Desktop Entry]
Name=wgeany
Comment=wgeany
Exec=wgeany %f
Type=Application
StartupNotify=false
Terminal=false
Categories=TextTools;
Name[en_US]=wgeany

Also you might want to include a line directing to the correct geany icon (Icon=path/icon.png) but I did not bother to find it. Save the file and now your batch file should turn up in the open with dialog. (You can set it to be the default application for a file type, say .txt, by going to properties for a file (of that type), then to the tab Open With and set wgeany as the default there.


Thanks also to MaxWilliams who helped me solve this.

0

If you use 'File' and 'Open', Geany will open the file in the current 'primary' instance, i.e. the Geany instance which you are currently using and not the first instance.

  • 1
    thanks @kpb, but if you read my question more carefully you'll see that I'm asking about opening a file from the terminal, or double-clicking it in the desktop, not from within geany. – Max Williams Jul 18 '16 at 12:43
0

geany.org documents his as follows :

use the following command to execute Geany on the current workspace:

geany --socket-file=/tmp/geany-sock-$(xprop -root _NET_CURRENT_DESKTOP | awk '{print $3}')

Now if you copy the system-wide geany.desktop file (from e.g. /usr/share/applications/) to your local applications directory (probably ~/.local/applications/), the local file seems to have precedence in both the GUI menus (tried Whisker and Xubuntu applications menu) and in file managers (tried thunar and spacefm).

So you can add the above --socket-file option in your local geany.desktop, to have 1 geany instance per workspace, or add the -i option suggested in other answers, to have one geany instance per invocation.

When starting geany from a command line, you can add of course any options you choose, and even include these in an alias, to have the same behaviour.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.