Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun mwn/url-transform (&optional to-url)
- "Replace characters in a URL. Some sites block links in posts. This is a
- workaround. Only works upon an active region. Default (no prefix)
- obscures the URL. With prefix (C-u most likely) restores the URL to a
- form that a browser will accept."
- (interactive "P")
- (when (region-active-p)
- (save-excursion
- (let ((beginning (region-beginning))
- (end (region-end))
- (pairs '((":" . "(colon)")
- ("/" . "(slash)")
- ("." . "(dot)"))))
- (cl-labels ((f (pair)
- (let* ((from-str (if to-url (cdr pair) (car pair)))
- (to-str (if to-url (car pair) (cdr pair)))
- (adjust (- (length to-str) (length from-str))))
- (goto-char beginning)
- (while (search-forward from-str end t)
- (replace-match to-str)
- (setq end (+ end adjust))))))
- (mapc #'f pairs))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement