ELisp: URL Percent Encode/Decode using JavaScript

By Xah Lee. Date: . Last updated: .

Here's a example of calling external script from emacs lisp to transform current region.


We want to decode percent encoded URL. See: ELisp: URL Percent Decode/Encode.


JavaScript has a function decodeURIComponent that does exactly what we need. [see JavaScript Encode URL, Escape String]

Here's the JavaScript code:

// -*- coding: utf-8 -*-
// 2014-01-11

// take a URI from stdin, percent decode it to stdout
// called from emacs


process.stdin.on('data', function(chunk) {

You need Node.js installed to run JavaScript script.

Here's the emacs lisp wrapper command:

(defun xah-decode-uri (p1 p2)
  "percent decode URI for text selection

Requires a node.js script. See code."
  (interactive "r")
  (let ((scriptName "/usr/bin/node /home/xah/git/xahscripts/emacs_uri_decode.js"))
      (shell-command-on-region p1 p2 scriptName nil "REPLACE" nil t))))

For how to write a elisp wrapper in general, see: ELisp: Command Wrapper Calling Shell, Python Code.

Emacs, Percent Encode/Decode Url

Emacs Wrapper for External Command