google搜索跳转链接及一些的Elisp函数整理备忘

scinart posted @ 2013年7月27日 23:46 in 未分类 , 7941 阅读

问题,google 搜索的链接时常打不开。

由于我没找到什么好方法让它使用代理,又鉴于谷歌搜索是明文链接,所以干脆把它的链接挖出来。

这里提供了一个url decode的代码。就是把诸如%2F变成/ 之类的。http://stackoverflow.com/questions/611831/how-to-url-decode-a-string-in-emacs-lisp

(line-beginning-position) 返回行首位置 区别(beginning-of-line),移光标到行首,返回nil

(line-end-position)返回行尾位置 区别(end-of-line)

(string-match REGEXP STRING &OPTIONAL START)返回regexp在string中的起始位置,从start开始

(region-active-p)当前是否有高亮,详见http://ergoemacs.org/emacs/emacs_region.html

(interactive "r")关于这个请见http://ergoemacs.org/emacs/elisp_command_working_on_string_or_region.html  Use of (interactive)部分

(delete-and-extract-region) 删除并返回region作为string

(kill-new STRING &optional REPLACE) 把string push 到 kill-ring 中,或替换到kill-ring顶层

 

整理出来的函数

(defun decode-google-link (string &optional start end)
  "extract url in google jump link
param string is not used"
  (interactive
    (if (region-active-p)
    (list nil (region-beginning) (region-end))
      (let ((p (point))
        (b (line-beginning-position))
        (e (line-end-position)))
    (list nil b e))))
  (let* ((string (buffer-substring-no-properties start end))
     (b (string-match "http" string 4))
     (e (string-match "&ei=" string b)))
    (kill-new (url-unhex-string (substring string b e)))))

Avatar_small
依云 说:
2013年7月28日 01:17

呃,似乎我那个 GreaseMonkey 可以干掉那些链接。

Avatar_small
scinart 说:
2013年8月04日 21:44

@依云: GreaseMonkey爽啊,受教了。


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter