[Date Prev][Date Next][Thread Prev][][Date Index][Thread Index]

禁則



w3m は禁則処理をしないので、shimbun で記事を読んでいると、行の頭
に「。」や「、」などが現れて気持ち悪いです。そこで、禁則を自前で
行なう hook を作ってみました。要は `fill-region' を行ないます。
これは Gnus 用ですが、

(eq major-mode 'gnus-article-mode)

の部分を変えれば、他の MUA でも使えると思います。

たいていうまく処理しますが、ときどき株式市況の記事などで、だめに
なることもあります。

--8<---------------cut here---------------start------------->8---
(defun my-w3m-refill-article ()
  "Refill article to perform kinsoku."
  (when (eq major-mode 'gnus-article-mode)
    (let ((fill-column (- (window-width) 4)))
      ;; Exclude signature.
      (goto-char (point-max))
      (when (and (re-search-backward "^-- $" nil t)
		 (not (search-forward "\n\n" nil t)))
	(narrow-to-region (point-min) (match-beginning 0)))
      ;; Remove trailing whitespace.
      (goto-char (point-min))
      (while (re-search-forward " +$" nil t)
	(delete-region (match-beginning 0) (match-end 0)))
      (goto-char (point-min))
      (while (re-search-forward "^[^\n]" nil t)
	(save-restriction
	  ;; Narrow to a paragraph.
	  (narrow-to-region (match-beginning 0)
			    (if (search-forward "\n\n" nil t)
				(1- (match-end 0))
			      (point-max)))
	  ;; Concatenate succeeding lines.
	  (goto-char (point-min))
	  (while (not (eobp))
	    (while (progn
		     (end-of-line)
		     (and
		      (< (point) (1- (point-max)))
		      (> (current-column) (1+ fill-column))
		      (not (and (memq (char-syntax (char-before))
				      '(?\) ?_))
				(< (1+ (point)) (point-max))
				(memq (char-syntax (char-after (1+ (point))))
				      '(?  ?\( ?_))))))
	      (delete-char 1))
	    (forward-line 1))
	  ;; Skip short lines.
	  (goto-char (point-min))
	  (end-of-line)
	  (while (and (not (eobp))
		      (<= (current-column) (1+ fill-column)))
	    (end-of-line 2))
	  ;; Fill long lines.
	  (unless (eobp)
	    (goto-char (point-min))
	    (while (not (eobp))
	      (end-of-line)
	      (if (> (current-column) (1+ fill-column))
		  (save-restriction
		    (narrow-to-region (point-at-bol)
				      (progn
					(forward-line 1)
					(point)))
		    ;;(shimbun-japanese-hankaku-region (point-min) (point-max))
		    (fill-region (point-min) (point-max)))
		(forward-line 1))))
	  (goto-char (point-max))))
      (widen))))

(add-hook 'w3m-fontify-after-hook 'my-w3m-refill-article)
--8<---------------cut here---------------end--------------->8---
-- 
山岡