トップ «前の日記(2006-01-30 (Mon)) 最新 次の日記(2006-02-05 (Sun))» 編集

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

最近なんにもやっていませんが、なにかやったらこちらに置くようにしています。
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|


2006-01-31 (Tue) [長年日記]

小技 その一

mew-dist で konqueror からの mailto インタフェースを書いた。どうやら動いたらしいが、使ったこともないくせに良く書くわ、おいら ^^;;;
(defun konqueror-compose-mail (&optional to subj cc dcc body attach)
  "Interface function of konqueror for `compose-mail'.
call with `(konqueror-compose-mail \"%t\" \"%s\" \"%c\" \"%b\" \"%B\" \"%A\")."
  (interactive)
  (let ((headers '(cc dcc body))
	others)
    (while headers
      (when (eval (car headers))
	(setq others (cons (cons (capitalize (symbol-name (car headers)))
				 (eval (car headers)))
			   others)))
      (setq headers (cdr headers)))
;;    (mew-user-agent-compose to subj others))) ;; <= お好みでこっちでもよい
    (compose-mail to subj others)))
konqueror って コンケラ って読むのね。知らんかった。Mew 以外で使うときは "dcc" を "bcc" にした方が良いのかな?

小技 その二

朝日新聞とか読売新聞のサイトが変わってから emacs-w3m で読みにくくなったので、M-k とすると本文だけ抽出するもの。前から存在していたのだけど、w3m の build 方法?に依存して動いたり動かなかったりするのを直したつもりなので、公開。普段使わないし、従来 M-k に割り当てられていた cookie の編集は M-K へ。
(add-hook 'w3m-mode-hook
	  (lambda ()
	    (define-key w3m-mode-map "\M-k" 'w3m-shimbun-extract)
	    (define-key w3m-mode-map "\M-K" 'w3m-cookie)))
  
(setq w3m-filter-rules
      `(("\\`http://www\\.geocities\\.co\\.jp/"
	 w3m-filter-delete-regions
	 "<DIV ALIGN=CENTER>\n<!--*/GeoGuide/*-->" "<!--*/GeoGuide/*-->\n</DIV>")
	("\\`http://[a-z]+\\.hp\\.infoseek\\.co\\.jp/"
	 w3m-filter-delete-regions
	 "<!-- start AD -->" "<!-- end AD -->")
	("\\`http://linux\\.ascii24\\.com/linux/"
	 w3m-filter-delete-regions
	 "<!-- DAC CHANNEL AD START -->" "<!-- DAC CHANNEL AD END -->")
	("\\`http://www.?\\.asahi\\.com/" w3m-filter-asahi-kiji) ;; 置き換え
	("\\`http://www.?\\.yomiuri\\.co\\.jp/" w3m-filter-yomiuri-kiji))) ;; 追加
  
(defvar w3m-shimbun-extract nil)
  
(defun w3m-filter-asahi-kiji (url)
  "Convert entity reference of UCS."
  (when w3m-use-mule-ucs
    (goto-char (point-min))
    (let ((case-fold-search t)
	  end ucs)
      (while (re-search-forward "alt=\"\\([^\"]+\\)" nil t)
	(goto-char (match-beginning 1))
	(setq end (set-marker (make-marker) (match-end 1)))
	(while (re-search-forward "&#\\([0-9]+\\);" (max end (point)) t)
	  (setq ucs (string-to-number (match-string 1)))
	  (delete-region (match-beginning 0) (match-end 0))
	  (insert-char (w3m-ucs-to-char ucs) 1)))))
  (when (eq w3m-shimbun-extract t)
    (setq w3m-shimbun-extract 'ok)
    (let (start end)
      (goto-char (point-min))
      (when (search-forward "</head>" nil t)
	(setq start (match-end 0))
	(when (search-forward "<div id=\"kijih\">" nil t)
	  (delete-region start (match-beginning 0))
	  (when (and (search-forward "<div class=\"wrapkiji\">" nil t)
		     (search-forward "alt=\"ここから広告です\"" nil t)
		     (search-backward "<" nil t))
	    (setq start (match-beginning 0))
	    (when (search-forward "</body>" nil t)
	      (delete-region start (match-beginning 0)))
	    (goto-char (point-min))
	    (while (re-search-forward "<table [^>]+>" nil t)
	      (delete-region (match-beginning 0) (match-end 0)))
	    (goto-char (point-min))
	    (while (search-forward "</table>" nil t)
	      (delete-region (match-beginning 0) (match-end 0)))))))))
  
(defun w3m-filter-yomiuri-kiji (url)
  "Convert entity reference of UCS."
  (when (eq w3m-shimbun-extract t)
    (setq w3m-shimbun-extract 'ok)
    (let (start end)
      (goto-char (point-min))
      (when (search-forward "</head>" nil t)
	(setq start (match-end 0))
	(when (search-forward "<!--// headline_start //-->" nil t)
	  (delete-region start (match-beginning 0))
	  (when (search-forward "<!--// article_end //-->" nil t)
	    (setq start (match-end 0))
	    (when (search-forward "</body>" nil t)
	      (delete-region start (match-beginning 0)))))))))
  
(defun w3m-shimbun-extract ()
  (interactive)
  (if (not (and w3m-current-url
		(or
		 (string-match "\\`http://[^.]+\\.asahi\\.com/" w3m-current-url)
		 (string-match "\\`http://[^.]+\\.yomiuri\\.co\\.jp/" w3m-current-url))))
      (message "読売新聞と朝日新聞だけよ")
    (setq w3m-shimbun-extract t)
    (w3m-redisplay-this-page)
    (when (eq w3m-shimbun-extract 'ok)
      (goto-char (point-min))
      (forward-line 1))
    (setq w3m-shimbun-extract nil)))
適当なので、だめなときはだめ。sb-asahi|yomiuri の機能を使うと良いかもしれない。

とっさに増えた ^^;; 小技その三

最初、上に張った <pre> がぼろぼろでした。
(defun tdiary-pre-conv ()
  (interactive)
  (let (beg end)
    (save-excursion
      (beginning-of-line)
      (cond
       ((looking-at "^<pre>")
	(setq beg (progn (forward-line 1) (point)))
	(re-search-forward "^</pre>")
	(setq end (progn (forward-line -1) (line-end-position))))
       ((looking-at "^</pre>")
	(setq end (progn (forward-line -1) (line-end-position)))
	(re-search-backward "^<pre>")
	(setq beg (progn (forward-line 1) (point))))
       (t
	(re-search-backward "^<pre>")
	(setq beg (progn (forward-line 1) (point)))
	(re-search-forward "^</pre>")
	(setq end (progn (forward-line -1) (line-end-position)))))
      (save-restriction
	(widen)
	(narrow-to-region beg end)
	(goto-char (point-min))
	(while (re-search-forward "^$" nil t)
	  (replace-match "  "))
	(goto-char (point-min))
	(while (search-forward "<" nil t)
	  (replace-match "<"))
	(goto-char (point-min))
	(while (search-forward ">" nil t)
	  (replace-match ">"))
	(goto-char (point-min))))))

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