txe

on-a-look-up-el-script

txe
Aug 3rd, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 6.05 KB | None | 0 0
  1. ;;change default browser for 'browse-url'  to w3m
  2. ;; A look-up script I found (sorry cannot say quick where out) & not without changes I tried & not without functions (e.g. the 'reddit' one) which could get improved but I got as 'TODO'  
  3. (setq browse-url-browser-function 'w3m-goto-url-new-session)
  4. (setq w3m-use-cookies t)                ;added
  5.  
  6. ;;change w3m user-agent to android
  7. (setq w3m-user-agent "Mozilla/5.0 (Linux; U; Android 2.3.3; zh-tw; HTC_Pyramid Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.")
  8.  
  9. ;;quick access hacker news
  10. (defun hn ()
  11.   (interactive)
  12.   (browse-url "http://news.ycombinator.com"))
  13.  
  14. ;;quick access reddit
  15. (defun reddit (reddit)
  16.   "Opens the REDDIT in w3m-new-session"
  17.   (interactive (list
  18.                 (read-string "Enter the reddit (default: psycology): " nil nil "psychology" nil)))
  19.   (browse-url (format "http://m.reddit.com/r/%s" reddit))
  20.   )
  21.  
  22. ;;i need this often
  23. (defun wikipedia-search (search-term)
  24.   "Search for SEARCH-TERM on wikipedia"
  25.   (interactive
  26.    (let ((term (if mark-active
  27.                    (buffer-substring (region-beginning) (region-end))
  28.                  (word-at-point))))
  29.      (list
  30.       (read-string
  31.        (format "Wikipedia (%s):" term) nil nil term)))
  32.    )
  33.   (browse-url
  34.    (concat
  35.     "http://en.m.wikipedia.org/w/index.php?search="
  36.     search-term
  37.     )))
  38.  
  39. ;; & cloning the above for googling, by me ~~`
  40. (defun goog-search (search-term)
  41.   "Search for SEARCH-TERM on wikipedia"
  42.   (interactive
  43.    (let ((term (if mark-active
  44.                    (buffer-substring (region-beginning) (region-end))
  45.                  (word-at-point))))
  46.      (list
  47.       (read-string
  48.        (format "pls, goog-for-this: (%s):" term) nil nil term)))
  49.    )
  50.   (browse-url
  51.    (concat
  52.     "http://www.google.com/search?ie=utf-8&oe=utf-8&q=%s"
  53.     search-term
  54.     )))
  55.  
  56. (global-set-key (kbd "s-f") 'goog-search)  
  57.  
  58. ;;when I want to enter the web address all by hand
  59. (defun w3m-open-site (site)
  60.   "Opens site in new w3m session with 'http://' appended"
  61.   (interactive
  62.    (list (read-string "Enter website address(default: w3m-home):" nil nil w3m-home-page nil )))
  63.   (w3m-goto-url-new-session
  64.    (concat "http://" site)))
  65.  
  66. ;;here a global call
  67. (global-set-key (kbd "s-l") 'w3m-open-site)
  68.  
  69. ;;;
  70. (defadvice org-open-at-point (around org-open-at-point-choose-browser activate)
  71.   (let ((browse-url-browser-function
  72.          (cond ((equal (ad-get-arg 0) '(4))
  73.                 'browse-url-generic)
  74.                ((equal (ad-get-arg 0) '(16))
  75.                 'choose-browser)
  76.                (t
  77.                 (lambda (url &optional new)
  78.                   (w3m-browse-url url t)))
  79.                )))
  80.     ad-do-it))
  81.  
  82.  
  83.  
  84. ;;;keymap https://www.emacswiki.org/emacs/WThreeMKeymap
  85. (let ((map (make-keymap)))
  86.    (suppress-keymap map)
  87.    (define-key map [backspace] 'w3m-scroll-down-or-previous-url)
  88.    (define-key map [delete] 'w3m-scroll-down-or-previous-url)
  89.    ;(define-key map "\C-?" 'w3m-scroll-down-or-previous-url)
  90.    (define-key map "\t" 'w3m-next-anchor)
  91.    (define-key map [(shift tab)] 'w3m-previous-anchor)
  92.    (define-key map [(shift iso-lefttab)] 'w3m-previous-anchor)
  93.    (define-key map "\C-m" 'w3m-view-this-url)
  94.    (define-key map [(shift return)] 'w3m-view-this-url-new-session)
  95.    (define-key map [(shift kp-enter)] 'w3m-view-this-url-new-session)
  96.    (define-key map [(button2)] 'w3m-mouse-view-this-url)
  97.    (define-key map [(shift button2)] 'w3m-mouse-view-this-url-new-session)
  98.    (define-key map " " 'scroll-up)
  99.    (define-key map "a" 'w3m-bookmark-add-current-url)
  100.    (define-key map "\M-a" 'w3m-bookmark-add-this-url)
  101.    (define-key map "+" 'w3m-antenna-add-current-url)
  102.    (define-key map "A" 'w3m-antenna)
  103.    (define-key map "c" 'w3m-print-this-url)
  104.    (define-key map "C" 'w3m-print-current-url)
  105.    (define-key map "d" 'w3m-download)
  106.    (define-key map "D" 'w3m-download-this-url)
  107.    ;; (define-key map "D" 'w3m-download-with-wget)
  108.    ;; (define-key map "D" 'w3m-download-with-curl)
  109.    (define-key map "g" 'w3m-goto-url)
  110.    (define-key map "G" 'w3m-goto-url-new-session)
  111.    (define-key map "h" 'describe-mode)
  112.    (define-key map "H" 'w3m-gohome)
  113.    (define-key map "I" 'w3m-toggle-inline-images)
  114.    (define-key map "\M-i" 'w3m-save-image)
  115.    (define-key map "M" 'w3m-view-url-with-external-browser)
  116.    (define-key map "n" 'w3m-view-next-page)
  117.    (define-key map "N" 'w3m-namazu)
  118.    (define-key map "o" 'w3m-history)
  119.    (define-key map "O" 'w3m-db-history)
  120.    (define-key map "p" 'w3m-view-previous-page)
  121.    (define-key map "q" 'w3m-close-window)
  122.    (define-key map "Q" 'w3m-quit)
  123.    (define-key map "R" 'w3m-reload-this-page)
  124.    (define-key map "s" 'w3m-search)
  125.    (define-key map "u" 'w3m-view-parent-page)
  126.    (define-key map "v" 'w3m-bookmark-view)
  127.    (define-key map "W" 'w3m-weather)
  128.    (define-key map "=" 'w3m-view-header)
  129.    (define-key map "\\" 'w3m-view-source)
  130.    (define-key map "?" 'describe-mode)
  131.    (define-key map ">" 'scroll-left)
  132.    (define-key map "<" 'scroll-right)
  133.    (define-key map "." 'beginning-of-buffer)
  134.    (define-key map "^" 'w3m-view-parent-page)
  135.    (define-key map "]" 'w3m-next-form)
  136.    (define-key map "[" 'w3m-previous-form)
  137.    (define-key map "}" 'w3m-next-image)
  138.    (define-key map "{" 'w3m-previous-image)
  139.    (define-key map "\C-c\C-c" 'w3m-submit-form)
  140.    (setq dka-w3m-map map))
  141.  
  142.  
  143.  (add-hook 'w3m-mode-hook '(lambda () (use-local-map dka-w3m-map)))
  144.  
  145.  
  146. (global-set-key (kbd "s-g") (lambda ()
  147.                          (interactive)
  148.                          (let ((current-prefix-arg t))
  149.                            (call-interactively 'w3m-search))))
  150.  
  151. (require 'w3m-search)
  152.  
  153. (add-to-list 'w3m-search-engine-alist
  154.              '("emacs-wiki" "http://www.emacswiki.org/cgi-bin/wiki.pl?search=%s"))
  155.  
  156. (add-to-list 'w3m-search-engine-alist
  157.              '("The-CMU-Pronouncing-Dic" "http://www.speech.cs.cmu.edu/cgi-bin/cmudict?in=%s"))
  158.  
  159. (add-to-list 'w3m-search-engine-alist
  160.              '("skell" "https://skell.sketchengine.co.uk/run.cgi/concordance?lpos=&query=%s"))
  161.  
  162.  
  163. (provide 'web-quick)
  164.  
  165. ;;; web-quick.el ends here
Add Comment
Please, Sign In to add comment