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

Re: w3m-end-of-line, kill-line should stop at whitespace

>>>>> In [emacs-w3m : No.10152] jidanni@xxxxxxxxxxx wrote:

> On the Location: line at the top of a page do C-e (w3m-end-of-line),
> it should stop at the last character. Not the end of the screen.
> Do C-k and then paste later with C-y, you'll see all these blanks appended:
> "Location: http://en.wikipedia.org/wiki/Who_Let_the_Dogs_Out%3F             "
>                                                                ^^^^^^^^^^^^^
> I notice the same problem with any text in HTML <div align="center"> too.
> emacs-w3m-version "1.4.263"

I have two ideas, though I think each of them is not good enough.

1. Remove those trailing whitespaces.

 (lambda nil
   (let ((inhibit-read-only t))
     (goto-char (point-min))
     (while (re-search-forward " +$" nil t)
       (delete-region (match-beginning 0) (match-end 0))))))

2. Modify `w3m-end-of-line' so that it moves the point to the end
   of non-whitespace characters first and moves the point to the
   real end of the line at the second time.  For `C-k', bind the
   key to the new function `w3m-kill-line'.

--8<---------------cut here---------------start------------->8---
(defun w3m-end-of-line (&optional arg)
  "Move the point to the end of the line and scroll the window left.
It makes the ends of upper and lower three lines visible.  If
`truncate-lines' is nil, it works identically as `end-of-line'."
  (interactive "P")
  (if truncate-lines
	(when (listp arg)
	  (setq arg (car arg)))
	(when arg
	  (next-line (1- arg)))
	(let ((inhibit-point-motion-hooks t)
	  (unless (prog1
		      (looking-at " *$")
	    (skip-chars-backward " "))
	  (setq home (point)
		arg (current-column))
	  (dolist (n '(-3 -2 -1 1 2 3))
	    (forward-line n)
	    (setq arg (max (current-column) arg))
	    (goto-char home)))
	(setq temporary-goal-column arg
	      this-command 'next-line)
	(w3m-set-window-hscroll (selected-window)
				(max (- arg (window-width) -2) 0)))
    (set-window-hscroll (selected-window) 0)
    (end-of-line arg)))

(defun w3m-kill-line ()
  "Add the rest of the current line to the `kill-ring'.
Whitespace around the text is ignored."
  (let ((deactivate-mark nil))
    (kill-new (if (looking-at " *\\([^\n ]+\\(?: *[^\n ]+\\)*\\)")
		  (match-string 1)

(define-key w3m-mode-map "\C-k" 'w3m-kill-line)
--8<---------------cut here---------------end--------------->8---