Skip to content

Instantly share code, notes, and snippets.

@hyagni
hyagni / enhanced-keyboard-quit.js
Created March 31, 2011 01:44
By hooking KeyBoardQuit on keysnail, disable caret browse mode and hide panorama with C-g. C-g means that I want to back to normal browsing.
hook.setHook('KeyBoardQuit', function (aEvent) {
if (key.currentKeySequence.length) {
return;
}
command.closeFindBar();
var marked = command.marked(aEvent);
if (util.isCaretEnabled()) {
if (marked) {
command.resetMark(aEvent);
} else {
@hyagni
hyagni / extended-anything-c-source-elscreen.el
Created March 23, 2011 04:05
Original c-source cannot select more than 10 screens, because of the way it gets a screen number. This new code can select any screen.
(defun elscreen-get-screen-num-from-candidate (candidate)
(string-match "\\[\\([0-9]+\\)\\]" candidate)
(string-to-number (match-string 1 candidate))
)
;; copied from anything-config.el
(setq anything-c-source-elscreen
'((name . "Elscreen")
(candidates . (lambda ()
(if (cdr (elscreen-get-screen-to-name-alist))
(sort
@hyagni
hyagni / skk-with-view-mode.el
Created February 26, 2011 14:06
view-mode にはいるときに skk をきり、でるときにもどします。
(defun view-mode-hook0 ()
(define-many-keys view-mode-map pager-keybind)
(hl-line-mode 1)
;; (column-highlight-mode 1)
;; is skk-mode loaded?
;; it is not be able to changed after startup.
(when (and (boundp 'skk-mode) skk-mode)
(skk-mode -1)
(setq skk-was-on t)))
(add-hook 'view-mode-hook 'view-mode-hook0)
@hyagni
hyagni / command-logger.el
Created February 26, 2011 14:02
logging all the commands
(setq my-log-key-counter 0)
(defun my-log-key (&optional acmd)
(let
((cmd (symbol-name (or acmd this-command)))
(file "~/logging"))
(save-current-buffer
(set-buffer (get-buffer-create "logging"))
(when (= 0 my-log-key-counter)
(insert-file-contents-literally file))
(goto-char (point-max))
@hyagni
hyagni / get-free-disk-gb.el
Created February 26, 2011 13:57
make get-free-disk-space human readable (especially for dired)
(defadvice get-free-disk-space (after get-free-disk-gb activate)
"Return free disk space with GByte order"
(let ((kb (string-to-number ad-return-value))) ; this is reserved variable
(if (> kb 1024)
(progn (setq kb (/ kb 1024))
(if (> kb 1024)
(setq ad-return-value (format "%.0f GB" (/ kb 1024)))
(setq ad-return-value (format "%.0f MB" kb))))
(setq ad-return-value (format "%.0f kB" kb))
)))
@hyagni
hyagni / use-trash.el
Created February 26, 2011 13:52
On Ubuntu, use trash instead of rm/rmdir. trash is part of trash-cli.
;; use trash for remove files
(defun my-trash-file (FILENAME)
(call-process-shell-command (concat "trash " FILENAME)
nil 0))
;; call-process-shell-command doesnt wait, with BUFFER 0
(defalias 'delete-file 'my-trash-file)
(defalias 'delete-directory 'my-trash-file)
@hyagni
hyagni / brief.patch
Created February 23, 2011 14:24
This patch makes brief gReader-like.
diff -Naur old/content/brief-overlay.xul new/content/brief-overlay.xul
--- old/content/brief-overlay.xul 2010-12-19 04:37:16.000000000 +0900
+++ new/content/brief-overlay.xul 2011-02-23 22:38:31.000000000 +0900
@@ -12,21 +12,21 @@
<key id="Brief_open" key="d" modifiers="accel alt"
oncommand="Brief.open()"/>
- <key id="Brief_selectNextEntry" key="j"
- oncommand="Brief.doCommand('selectNextEntry')"/>
- <key id="Brief_selectPreviousEntry" key="k"
@hyagni
hyagni / keysnail-open-delicious-bookmark.js
Created November 30, 2010 11:30
Add to delicious bookmark shortcut in keysnail. Bookmarklet like motion.
key.setViewKey(['C-c', 'C-d'], function () {
f='http://www.delicious.com/save?url='+encodeURIComponent(getBrowser().contentDocument.URL)+'&title='+encodeURIComponent(getBrowser().contentDocument.title)+'&v=5&';
a=function(){
if(!window.open(f+'noui=1&jump=doclose','deliciousuiv5','location=yes,links=no,scrollbars=no,toolbar=no,width=550,height=550'))
location.href=f+'jump=yes'
};
if(/Firefox/.test(navigator.userAgent)){
setTimeout(a,0)
} else {
a()
@hyagni
hyagni / keysnail-amazon-BookInfo-Copy.js
Created November 30, 2010 11:22
On amazon pages, copy to clipboard the bookinfo (ASIN, author, title, URL) with C-cC-p
key.setViewKey(['C-c', 'C-p'], function(ev){
var loc = getBrowser().contentDocument.URL;
var doc = frame = document.commandDispatcher.focusedWindow.document
|| gBrowser.contentWindow.document;
if(loc.match(/www\.amazon\./)){
asin = loc.split("/")[5];
r = doc.evaluate("//div[@class='buying']",doc,null,XPathResult.FIRST_ORDERED_NODE_TYPE, null);
list = r.singleNodeValue.textContent.split("\n");
var info = Array();
for(i=0; i<list.length; i++ ){
@hyagni
hyagni / gist:642035
Created October 23, 2010 10:20
change navigation bar color with caret-browse mode in keysnail
key.setViewKey(['C-c', 'C-a'], function (ev) {
children = document.getElementById("nav-bar").children;
for(i=0; i<children.length; i++){
children[i].style.backgroundColor = "pink";
}
util.setBoolPref("accessibility.browsewithcaret", true);
}, "Start Caret-Browse Mode");
key.setCaretKey(['C-c', 'C-a'], function (ev) {
children = document.getElementById("nav-bar").children;