;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/w3m/w3m-url.el (require 'thingatpt) (require 'w3m) (defun w3m-cat-source () (interactive) (w3m-pipe-source w3m-current-url "/bin/cat") ) (defun goto-next-url () (interactive) (let ((beg (point)) (end (point-max))) (cl-dolist (url-type thing-at-point-uri-schemes) (goto-char beg) (when (re-search-forward url-type end t) (goto-char (match-beginning 0)) (let ((url (thing-at-point 'url))) (when url (w3m-goto-url url) (cl-return) )))))) ;; (goto-next-url) ; http://www.google.com (defun w3m-kill-url-and-title () (interactive) (let ((title (w3m-current-title)) (url w3m-current-url) ) (unless (string= title "") (kill-new (format "%s # %s" url title)) (message "%s" (current-kill 0)) ))) (defun w3m-kill-title () (interactive) (kill-new (w3m-current-title) ) (message "%s" (current-kill 0)) ) (defun append-string-to-file (str file &optional uniq) (unless (and uniq (xref-matches-in-files (regexp-quote str) (list file)) ) (append-to-file (format "%s\n" str) nil file) )) (defun w3m-kill-url-dwim () (interactive) (let*((url (or (w3m-anchor) (thing-at-point 'url) w3m-current-url)) (title (when (string= url w3m-current-url) (w3m-current-title))) (title-part (if title (format " ; %s" title) "")) (cmd (format "echo \"%s\" | xi" url)) ) (append-string-to-file (format "%s%s" url title-part) (format "%s/URL" (getenv "HOME")) t) (kill-new url) (shell-command cmd) ) (message "%s" (current-kill 0)) ) (defun w3m-goto-url-kill-current () (interactive) (when w3m-current-url (kill-new w3m-current-url) ) (call-interactively #'w3m-goto-url) ) (defun rfc (num) (interactive "nRFC: ") (w3m-browse-url (format "https://datatracker.ietf.org/doc/html/rfc%d" num) )) (defun w3m-view () (interactive) (w3m (buffer-file-name)) ) (defun w3m-browse-url-at-point () (interactive) (w3m (thing-at-point 'url)) ) (defun w3m-view-html () (interactive) (w3m-find-file (buffer-file-name)) ) (defun dired-view-in-w3m () (interactive) (w3m-find-file (dired-get-filename)) ) (provide 'w3m-url)