tags 367298 patch thanks Here's a suggestion how to get this to work, making reportbug attempt to use emacsclient so an existing instance of Emacs can be used to send the bug report. Since this involves a mix of Emacs Lisp, shell code and Python, it gets a bit messy, unfortunately. So, I've attached two patches; I'm not sure which one is preferable. The first patch is the most quick and dirty way to hack in support for this, while the other takes an object oriented approach, which perhaps is overkill.
Also, to get this to work I had to drop the use of an environment variable as the method to pass the name of the tempfile with the reportbug template to the Emacs Lisp code, because an existing Emacs process cannot see environment variables created by reportbug. Instead the filename will be passed as a parameter to the function tfheen-reportbug-insert-template in Emacs Lisp code. Note that this will only work with emacsclient for GNU Emacs version 22 and (hopefully) later, because earlier versions of emacsclient did not support the --eval option. Also note that users need to have (server-start) in their ~/.emacs file for this extension to be useful, or else will Emacs not listen for connections from emacsclient. Though, if emacsclient won't work because of either of these issues, or another reason, reportbug will work as before, with a new instance of Emacs being started and used instead. While not related to this issue, I also took the opportunity to make another couple of slight modificatons to reportbug.el. First I substituted the calls to string-to-int, that were used in the patch I submitted for #227153, by calls to string-to-number instead, as string-to-int now seems to be considered obsolete since Emacs 22.1. Secondly, I changed the function tfheen-reportbug-insert-template such that, in the buffer that is created for the reportbug template, the point will be positioned where it is natural to start typing the text which is to be filled in by the user reporting the bug. The patches are for reportbug 3.99.0.
--- a/reportbug/submit.py 2008-09-16 20:09:49.000000000 +0000 +++ b/reportbug/submit.py 2009-01-07 17:13:31.000000000 +0000 @@ -420,8 +420,7 @@ ewrite('Original write failed, wrote bug report to %s\n', msgname) if mua: - for bit in mua.split(): - if '%s' not in bit: break + bit = mua.rstrip(' \n').split('\n')[-1].split()[0] ewrite("Spawning %s...\n", bit or mua) if '%s' not in mua: mua += ' %s' --- a/reportbug/utils.py 2008-09-16 20:09:49.000000000 +0000 +++ b/reportbug/utils.py 2009-01-07 17:27:12.000000000 +0000 @@ -737,7 +737,14 @@ 'mutt' : 'mutt -H', 'af' : 'af -EH < ', 'mh' : '/usr/bin/mh/comp -use -file', - 'gnus' : 'REPORTBUG=%s emacs -l /usr/share/reportbug/reportbug.el -f tfheen-reportbug-insert-template', + 'gnus' : """ + REPORTBUG=%s + elisp="(progn + (load-file \\"/usr/share/reportbug/reportbug.el\\") + (tfheen-reportbug-insert-template \\"$REPORTBUG\\"))" + emacsclient --no-wait --eval "$elisp" 2>/dev/null || \\ + emacs --eval "$elisp" + """, } MUA['nmh'] = MUA['mh'] --- a/reportbug.el 2008-09-16 20:09:49.000000000 +0000 +++ b/reportbug.el 2008-11-11 19:37:07.000000000 +0000 @@ -10,10 +10,10 @@ (if (or ;; Check for a separately packaged release of Gnus ;; (second component of version number even): - (= (% (string-to-int (match-string 2 gnus-version-number)) 2) 0) + (= (% (string-to-number (match-string 2 gnus-version-number)) 2) 0) ;; Check for a separately packaged pre-release of Gnus ;; (first component of version number 0): - (= (string-to-int (match-string 1 gnus-version-number)) 0)) + (= (string-to-number (match-string 1 gnus-version-number)) 0)) (require 'gnus-load)) (defun tfheen-set-header (header value) @@ -24,10 +24,10 @@ (insert value) (widen)) -(defun tfheen-reportbug-insert-template () +(defun tfheen-reportbug-insert-template (reportbug-template) (interactive) (require 'gnus) - (find-file (getenv "REPORTBUG")) + (find-file reportbug-template) (let ((subject (message-fetch-field "Subject")) (toaddr (or (message-fetch-field "To") "sub...@bugs.debian.org"))) (gnus-narrow-to-body) @@ -37,5 +37,7 @@ (tfheen-set-header "To" toaddr) (gnus-narrow-to-body) (insert body) + (goto-char (point-min)) + (search-forward "\n\n" nil t) (widen))) - (kill-buffer (find-buffer-visiting (getenv "REPORTBUG")))) + (kill-buffer (find-buffer-visiting reportbug-template)))
--- a/reportbug/submit.py 2008-09-16 20:09:49.000000000 +0000 +++ b/reportbug/submit.py 2009-01-07 17:31:43.000000000 +0000 @@ -49,14 +49,6 @@ quietly = False -# Obscene hack :) -def system(cmdline): - try: - x = os.getcwd() - except OSError: - os.chdir('/') - os.system(cmdline) - ascii_range = ''.join([chr(ai) for ai in range(32,127)]) notascii = re.compile(r'[^'+re.escape(ascii_range)+']') notascii2 = re.compile(r'[^'+re.escape(ascii_range)+r'\s]') @@ -420,12 +412,8 @@ ewrite('Original write failed, wrote bug report to %s\n', msgname) if mua: - for bit in mua.split(): - if '%s' not in bit: break - ewrite("Spawning %s...\n", bit or mua) - if '%s' not in mua: - mua += ' %s' - system(mua % commands.mkarg(filename)[1:]) + ewrite("Spawning %s...\n", mua.name) + mua.send(filename) elif not failed and (using_sendmail or smtphost): if kudos: ewrite('\nMessage sent to: %s\n', sendto) --- a/reportbug/utils.py 2008-09-16 20:09:49.000000000 +0000 +++ b/reportbug/utils.py 2009-01-08 12:35:49.000000000 +0000 @@ -733,11 +733,49 @@ 'printonly', 'offline', 'check_uid', 'smtptls', 'smtpuser', 'smtppasswd', 'paranoid') +class Mua: + command = "" + name = "" + + def __init__(self, command): + self.command = command + self.name = command.split()[0] + + # Obscene hack :) + def system(self, cmdline): + try: + x = os.getcwd() + except OSError: + os.chdir('/') + os.system(cmdline) + + def send(self, filename): + mua = self.command + if '%s' not in mua: + mua += ' %s' + self.system(mua % commands.mkarg(filename)[1:]) + + +class Gnus(Mua): + name = "gnus" + + def __init__(self): + pass + + def send(self, filename): + elisp = """(progn + (load-file "/usr/share/reportbug/reportbug.el") + (tfheen-reportbug-insert-template "%s"))""" + filename = re.sub("[\"\\\\]", "\\\\\\g<0>", filename) + elisp = commands.mkarg(elisp % filename) + self.system("emacsclient --no-wait --eval %s 2>/dev/null" + " || emacs --eval %s" % (elisp, elisp)) + MUA = { - 'mutt' : 'mutt -H', - 'af' : 'af -EH < ', - 'mh' : '/usr/bin/mh/comp -use -file', - 'gnus' : 'REPORTBUG=%s emacs -l /usr/share/reportbug/reportbug.el -f tfheen-reportbug-insert-template', + 'mutt' : Mua('mutt -H'), + 'af' : Mua('af -EH < '), + 'mh' : Mua('/usr/bin/mh/comp -use -file'), + 'gnus' : Gnus(), } MUA['nmh'] = MUA['mh'] --- a/reportbug.el 2008-09-16 20:09:49.000000000 +0000 +++ b/reportbug.el 2008-11-11 19:37:07.000000000 +0000 @@ -10,10 +10,10 @@ (if (or ;; Check for a separately packaged release of Gnus ;; (second component of version number even): - (= (% (string-to-int (match-string 2 gnus-version-number)) 2) 0) + (= (% (string-to-number (match-string 2 gnus-version-number)) 2) 0) ;; Check for a separately packaged pre-release of Gnus ;; (first component of version number 0): - (= (string-to-int (match-string 1 gnus-version-number)) 0)) + (= (string-to-number (match-string 1 gnus-version-number)) 0)) (require 'gnus-load)) (defun tfheen-set-header (header value) @@ -24,10 +24,10 @@ (insert value) (widen)) -(defun tfheen-reportbug-insert-template () +(defun tfheen-reportbug-insert-template (reportbug-template) (interactive) (require 'gnus) - (find-file (getenv "REPORTBUG")) + (find-file reportbug-template) (let ((subject (message-fetch-field "Subject")) (toaddr (or (message-fetch-field "To") "sub...@bugs.debian.org"))) (gnus-narrow-to-body) @@ -37,5 +37,7 @@ (tfheen-set-header "To" toaddr) (gnus-narrow-to-body) (insert body) + (goto-char (point-min)) + (search-forward "\n\n" nil t) (widen))) - (kill-buffer (find-buffer-visiting (getenv "REPORTBUG")))) + (kill-buffer (find-buffer-visiting reportbug-template)))