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

Re: Bug#728501: w3m-el: mew-w3m-region & multiple blockquote


As an alternative solution, I have been using the replacement of
`mew-w3m-region` below.  Comments are welcome.  I had no time to try
the proposed patch yet.

My 0.02,

(defun mew-w3m-insert-quote-mark ()
  "We assume to be the beginning of a line.  Skip any HTML tags
to the data.  This is to put the quotation mark right before the
  (catch 'Break
    (while (looking-at "[ \t\f\n]*<\\(/?[a-zA-Z]+\\)\\([ \t\f\n]+[^>]*\\)?>")
      (let ((tag (buffer-substring (match-beginning 1) (match-end 1)))
	    (tagbeg (match-beginning 0))
	    (tagend (match-end 0)))
	 ((string-equal tag "br")
	  (goto-char tagbeg)
	  (insert mew-w3m-region-cite-mark)
	  (goto-char tagend))
	 ((member tag '("ul" "/ul" "ol" "/ol"))
	  (delete-region tagbeg tagend))
	 ((string-equal tag "li")
	  ;; Replace <li> to put the mark at the beginning of the line.
	  (delete-region tagbeg tagend)
	  (insert mew-w3m-region-cite-mark " * ")
	  (throw 'Break nil)
	 ((string-equal tag "/li")
	  (delete-region tagbeg tagend)
	  (insert "<br/>")
	  (throw 'Break nil)
	  (goto-char tagend)))))
    (insert mew-w3m-region-cite-mark)))

(defun mew-w3m-region (start end &optional url charset)
  "w3m-region with inserting the cite mark."
  (if (null mew-w3m-region-cite-mark)
      (w3m-region start end url charset)
      (narrow-to-region start end)
      (let ((case-fold-search t)
	    (has-blockquote nil)
	    lines tagbeg0 tagend0 tagbeg1 tagend1)
	(goto-char (point-min))
	(while (w3m-search-tag "blockquote")
	  (setq has-blockquote t)
	  (setq tagbeg0 (match-beginning 0))
	  (setq tagend0 (match-end 0))
	  (when (w3m-end-of-tag "blockquote" t)
	    (setq tagend1 (point))
	    (re-search-backward "</ *blockquote")
	    (setq tagbeg1 (match-beginning 0))
	    (setq lines (buffer-substring tagend0 tagbeg1))
	    (delete-region tagbeg0 tagend1)
	    (insert (with-temp-buffer
		      (insert lines)
		      (goto-char (point-min))
		      ;; <div> also start new lines.
		      (while (w3m-search-tag "br" "/div" "div")
			;; <br><div>* is a single new line
		      (buffer-substring (point-min) (point-max))))
	    (goto-char (point-min)); deal with other <blockquote>
	(let ((f w3m-fill-column))
	  (setq w3m-fill-column (if has-blockquote 8192 0))
	  (w3m-region (point-min) (point-max) url charset)
	  (setq w3m-fill-column f)))