トップ 最新 追記

猫熊は燃えつきた?!日記

最近なんにもやっていませんが、なにかやったらこちらに置くようにしています。
2002|12|
2003|01|02|03|04|05|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|
2011|09|
2012|02|


2012-02-07 (Tue) [長年日記]

w3m-goto-unseen-buffer

emacs-w3m でまだ読んでいない buffer に一発で飛ぶのが出来なかったような気がするので、quick hack してみた。後半の w3m-goto-buffer() は昔書いたものをちょっとだけ変更。
(unless (featurep 'xemacs)
  (add-hook 'w3m-mode-hook
	    (lambda ()
	      (let ((key1 ?\C-0)
		    (key2 ?\M-0)
		    (ch 0))
		(while (< ch 10)
		  (define-key w3m-mode-map (vector (+ key1 ch)) 'w3m-goto-buffer)
		  (define-key w3m-mode-map (vector (+ key2 ch)) 'w3m-goto-buffer)
		  (setq ch (1+ ch))))
	      (define-key w3m-mode-map "\M-u" 'w3m-goto-unseen-buffer))))
 
(defun w3m-goto-unseen-buffer ()
  "Goto next unseen w3m buffer."
  (interactive)
  (let* ((bufs (w3m-list-buffers))
	 (nowbuf (current-buffer))
	 current unseens0 unseens1 buf)
    (dolist (buf bufs)
      (when (w3m-unseen-buffer-p buf)
	(if current
	    (setq unseens1 (cons buf unseens1))
	  (setq unseens0  (cons buf unseens0))))
      (when (eq nowbuf buf)
	(setq current t)))
    (if unseens1
	(setq buf (car (nreverse unseens1)))
      (setq buf (car (nreverse unseens0))))
    (if buf
	(progn
	  (w3m-history-store-position)
	  (set-window-buffer (selected-window) buf)
	  (run-hooks 'w3m-select-buffer-hook)
	  (w3m-select-buffer-update))
      (message "No unseen buffer."))))
 
(defun w3m-goto-buffer (&optional arg)
  "Goto w3m buffer to accompany inputed numbers like the following,
C-2 => *w3m*<2>
M-0 => *w3m*
12M-3 => *w3m*<123>"
  (interactive "p")
  (let* ((num (+ (- (logand last-command-event ?\177) ?0)
		 (if (not current-prefix-arg)
		     0
		   (* arg 10))))
	 (bufs (w3m-list-buffers))
	 (max (length bufs))
	 buf bufname win)
    (when (>= num 0)
      (setq buf (if (or (= num 0) (> num max))
		    (nth (1- max) bufs)
		  (nth (1- num) bufs)))
      (setq bufname (when (and buf (buffer-live-p buf))
		      (buffer-name buf)))
      (if (not bufname)
	  (message "No exist w3m buffer")
	(cond
	 ((eq major-mode 'w3m-mode)
	  (w3m-history-store-position)
	  (set-window-buffer (selected-window) buf))
	 ((setq win (catch 'win
		      (walk-windows
		       (lambda (w)
			 (save-excursion
			   (set-buffer (window-buffer w))
			   (when (eq major-mode 'w3m-mode)
			     (throw 'win w)))))))
	  (select-window win)
	  (set-window-buffer win buf))
	 (t
	  (pop-to-buffer buf)))
	(w3m-history-restore-position)
	(run-hooks 'w3m-select-buffer-hook)
	(w3m-select-buffer-update)
	(message "Goto w3m buffer \"%s\"" bufname)))))

うーむ

ブランクが4年近くあるので、なんだか気に入らないコードだ。。。


書いている人: 白井秀行 (mailto:shirai@meadowy。org)
訪問して下さった人: 今日: 人, 昨日: , 過去: 人 (2007年5月10日から)
RDF Feed