emacs中搜索值包含特定字符串的所有变量
时间:2007-07-04 来源:hellwolf
在emacs中,有的扩展会自作主张的给你创建文件(夹),而你一时又不知道该用哪个变量控制,那么下面这个脚本可以帮上你的忙:
将上面的代码拷贝到你的dotEmacs
需要的时候输入M-x my-search-variables-by-value,然后按照提示输入一个regex即可在一个*Help* buffer中列出所有包含该regex的变量了。点击查看运行效果。
;;search variables by value使用方法:
(defun my-search-variables-by-value (r)
(interactive "MSearch variable match this regex :")
(with-output-to-temp-buffer "*Help*"
(with-current-buffer (get-buffer "*Help*")
(princ "Variables value matches ")
(let ((p (point)))
(princ (format "%s :\n\n" r))
(add-text-properties
p (point)
(list
'face 'bold)))
(mapatoms
(lambda (s)
(if (and (boundp s)
(stringp (symbol-value s))
(string-match r (symbol-value s)))
(progn
(let ((p (point))
(map (make-sparse-keymap)))
(define-key map [mouse-1]
(lambda (event)
(interactive "e")
(save-excursion
(mouse-set-point event)
(describe-variable
(intern (get-text-property (point) 'symname))))))
(princ (symbol-name s))
(add-text-properties
p (point)
(list
'symname (symbol-name s)
'face 'button
'mouse-face 'highlight
'keymap map))
(princ "\n")
(princ (concat (symbol-value s) "\n\n"))
))))))
(help-setup-xref (list #'my-search-variables-by-value r)
(interactive-p))
(print-help-return-message)))
将上面的代码拷贝到你的dotEmacs
需要的时候输入M-x my-search-variables-by-value,然后按照提示输入一个regex即可在一个*Help* buffer中列出所有包含该regex的变量了。点击查看运行效果。
相关阅读 更多 +










