Xfce Forum

Sub domains
 

You are not logged in.

#1 2022-12-04 17:09:35

jt1122
Member
Registered: 2021-03-26
Posts: 240

Mousepad - comment line shortcut

Hi,

Does MP have a keyboard shortcut for commenting lines (inserting # at the beginning)?.

~/.config/Mousepad/accels.scm didn't show anything relevant.

Thanks

Offline

#2 2022-12-04 17:17:37

Tamaranch
Member
Registered: 2020-12-31
Posts: 269

Re: Mousepad - comment line shortcut

No, you have to use search & replace, enable regular expressions, and replace (^.) with #\1.

Offline

#3 2022-12-04 17:18:33

jt1122
Member
Registered: 2021-03-26
Posts: 240

Re: Mousepad - comment line shortcut

Thanks. Is it possible to define this as a shortcut/macro?.

Offline

#4 2022-12-04 17:21:12

Tamaranch
Member
Registered: 2020-12-31
Posts: 269

Re: Mousepad - comment line shortcut

Unfortunately not, I thought several times to make macros like notepad++, but I never got to it smile

Offline

#5 2022-12-04 17:21:43

jt1122
Member
Registered: 2021-03-26
Posts: 240

Re: Mousepad - comment line shortcut

Thanks.

Offline

#6 2024-03-31 06:19:31

Signy
Member
Registered: 2020-10-20
Posts: 52

Re: Mousepad - comment line shortcut

There is a workaround on Linux - make a shortcut in AutoKey (I would use AutoHotKey on Windows, the script would be different). I use 2 python scripts (AutoKey only):

# Write (add) BASH comment in front of every line
import time, os

# Backup previous value of clipboard
try:
  oldClip = clipboard.get_clipboard()
  time.sleep(0.3)
except: 
  oldClip = ""
keyboard.send_keys("<ctrl>+c")
time.sleep(0.2)  

newClip = clipboard.get_clipboard()

# Use new filled clipboard
output = "#" + newClip.replace("\n","\n#")
clipboard.fill_clipboard(output)
time.sleep(0.3)
keyboard.send_keys("<ctrl>+v")
time.sleep(0.5)

# Revert clipboard
clipboard.fill_clipboard(oldClip)

del newClip, output, oldClip
# Remove BASH comment in front of every line
import time, os, re

# Backup previous value of clipboard
try:
  oldClip = clipboard.get_clipboard()
  time.sleep(0.2)
except: 
  oldClip = ""
keyboard.send_keys("<ctrl>+c")
time.sleep(0.2)  
  
newClip = clipboard.get_clipboard()

# Use new filled clipboard
output = newClip.replace("\n#","\n")
output = re.sub("^#", "", output)
clipboard.fill_clipboard(output)
time.sleep(0.2)
keyboard.send_keys("<ctrl>+v")
time.sleep(0.5)

# Revert clipboard
clipboard.fill_clipboard(oldClip)

del newClip, output, oldClip

Notes:

  • AutoKey allows you to set your own shortcut.

  • Window filter in AutoKey is strongly reccomended (for example mousepad\.Mousepad)

  • I use the  time.sleep() commands because AutoKey does not work very well on Xubuntu 20.04 or 22.04 - for example filling up clipboard this way takes some time, but AutoKey does not wait till the operation is finished. So I use a lot of sleep commands to be sure previous command is finished.

Offline

Board footer

Powered by FluxBB