58

Emacs as a StackExchange client?

How can I use Emacs to edit questions, answers, and comments here on the Emacs Stack Exchange site?

Broadly, what possible methods exist?

Kill and yank

This works, but the method is so cumbersome that it's not worth it for short posts or even medium-length posts.

Browser plugin

There is a relatively well know browser plugin for Firefox that lets your push the text content of any <textarea> back and forth between the editor of your choice. I presume it works via temp files and I haven't evaluated it. Using the plugin with emacs has been discussed on StackOverflow. I don't use Chrome any more.

Stack Exchange API

Something called Stack Exchange Mode for Emacs exists. I have not evaluated it. The source isn't too stale, but the project is obviously not completed.

Other options?

I seek suggestions!

Motivations

Regardless of what method is used to edit questions, answers, and comments in emacs, I am sure that doing so will enable us to do some common tasks with ease:

  • Adhere to conventions. Something like M-x record-keystrokes-and-write-them-out-as-markdown RET C-x C-s C-g RET ...might yield:

    C-x C-s C-g

  • Ask what an error message means: M-x post-region-on-emacs-se-as-question RET ...

  • I deliberately didn't mention in my question that I'm a Linux user. Should I? Of course, I use SE most often when I'm at work, where I do all my internet browsing in a Windows host and emacs work in a Linux VM... – daveloyall Oct 21 '14 at 19:27
  • Chrome Edit-with-emacs is not buggy for me... – mankoff Oct 21 '14 at 19:44
  • Would the user who deleted his or her Answer consider putting it back? There was a useful elisp function in there. Do unaccepted answers count against a user in some way I don't know about? – daveloyall Oct 21 '14 at 21:41
  • @daveloyall: I'm interested in what problems you had with the Chrome textarea solution (disclosure I am the maintainer of Edit with Emacs). I quite happily edit StackExchange posts with it and markdown-mode. – stsquad Oct 22 '14 at 13:03
  • @stsquad Well, I am not sure. I don't have it installed anymore, so I'm not sure what version I used. Ok, I did a little digging (only a little) and I found that many of the subject lines here github.com/stsquad/emacs_chrome/issues sound like the kind of thing that I encountered. Basically if the javascript on some site can make it not work, it's not what I'm looking for... Anyway, I stopped using Chrome when an update permanently disabled non-web-store extensions, like the little ones I wrote locally. – daveloyall Oct 22 '14 at 14:51
33

See the Stack Exchange for Emacs project. From their page:

SX will be a full featured Stack Exchange mode for GNU Emacs 24+. Using the official API, we aim to create a more versatile experience for the Stack Exchange network within Emacs itself.

screenshot

  • Artur Malabarba has promised to write a mode for it, see: twitter.com/bruceconnor/status/520692859109117952 I would recommend holding him to it :) – Lee H Oct 22 '14 at 10:48
  • @Malabarba I'm holding you to it! :) ...In fact, if this idea had a repo backing it, I'd be very tempted to accept it as an answer. Not that I'm the sole source of internet points or anything... – daveloyall Oct 22 '14 at 15:06
  • I'll stick to it. :-) current ETA is around Christmas. – Malabarba Oct 22 '14 at 17:09
  • 1
    How have I not seen this Q? :D Interestingly, the package works out-of-the-box on 24.3. @dharmatech -- would you mind posting that as an issue? – Sean Allred Dec 15 '14 at 15:37
  • 3
    Wow, just read this, installed sx.el from melpa, ran it and here I am writing a comment using it. Fantastic! – Tim X Feb 18 '15 at 7:44
11

edit-server might be of some help. It lets you edit any text field inside Chrome with Emacs and then send the text back to the browser with minimum effort. Not exactly what you wanted, but its an improvement.

7

I'm using w3m to submit this answer from within Emacs. The StackExchange sites don't look very nice in w3m, but submitting forms works just fine. (I've not been able to submit an answer with the new eww browser.)

I don't recommend actually doing this, because it seems rather painful compared to using a regular browser with a Emacs-like bindings (e.g. keysnail for Firefox).

EDIT: I had to solve a captcha to submit my answer. Unfortunately, no captcha was shown in the w3m buffer, so I had to visit the captcha URL in a traditional browser.

5

I have always found kill and yank to be sufficient, but I do have a stackoverflow specific copy function I use.

(defun copy-el-for-so (beg end)
  "copy region and format for SO."
  (interactive "r")
  (let ((text (buffer-substring-no-properties beg end)))
    (with-temp-buffer
      (insert "<!--Language: lang-lisp -->\n")
      (replace-string "\n" "\n    " nil (point)
                      (progn
                        (insert "\n" text)
                        (point)))
      (copy-region-as-kill (point-min) (point-max))
      (message "copied"))))

Which takes things like:

(defun process-exit-code-and-output (program &rest args)
  "Run PROGRAM with ARGS and return the exit code and output in a list."
  (with-temp-buffer
    (list (apply 'call-process program nil (current-buffer) nil args)
          (buffer-string))))

and turn them into:

<!--Language: lang-lisp -->

    (defun process-exit-code-and-output (program &rest args)
      "Run PROGRAM with ARGS and return the exit code and output in a list."
      (with-temp-buffer
        (list (apply 'call-process program nil (current-buffer) nil args)
              (buffer-string))))

Alternatively, I find the Edit With Emacs chrome extensions to be very nice.

  • 2
    I'd suggest Edit With Emacs as separate answer. And I find it nice too, and not buggy. – mankoff Oct 21 '14 at 19:44
5

Keysnail implements Emacs keybindings for Firefox. It also serves as a platform for plug-ins, extending the architecture of Firefox in a distinctively Emacsesque fashion.

  • 1
    It's worth mentioning that there is a plugin called K2Emacs for Keysnail, that let's you edit textareas in an external program (by default Emacs). – Omar Dec 5 '14 at 14:27
1

I have been using Firemacs and have been very happy with it. It is a firefox extension which gives you emacs keybinding. It supports many keybindings including kill and yank.

It can be installed from here.

1

You can use the Firefox add-on It's All Text. This will add a tiny "edit" button to the bottom of any text area. Clicking it (or using a hot-key, default C-S-v) fires up Emacs with the content in a temporary buffer. Write the buffer (repeatedly) and the text area updates.

My config for it is simply setting Editor to /usr/bin/emacsclient.

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.