简体   繁体   中英

(MATE) pluma "PLUMA_SELECTED_TEXT" is missing from environment

I'm writing a pluma plugin (in python) to automate HTML markup of a selected text. According to (the poor and scarce) documentation, the selected text in the editor should be found in os.environ["PLUMA_SELECTED_TEXT"] .

However, when I select some text, run my plugin and examine the environment there is no variable such as "PLUMA_SELECTED_TEXT" .

I do find 'PLUMA_CURRENT_LINE' but it contains only the last line of the selected text.

Here is the plugin itself (with debugging stuff...)

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import os
import re

print(os.environ)

try:
    ptext = os.environ["PLUMA_SELECTED_TEXT"]
except KeyError:
    ptext = "SELECTION NOT FOUND"

print(ptext)

#ptext = re.sub('\n','<br/>\n',ptext)
#ptext = "<p>\n%s\n</p>\n"%ptext

#print(ptext)

Anyone ran into this?

I found the solution, for the benefit of whoever runs into this.

The selected text is actually sent to the script as STDIN so this needs to be read.

Hence the code looks like that:

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import re
import sys


try:
    ptext = sys.stdin.read()
except:
    ptext = "SELECTION NOT FOUND"


ptext = re.sub('\n','<br/>\n',ptext)
ptext = "<p>\n%s\n</p>\n"%ptext

print(ptext)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM