Skip to content

Instantly share code, notes, and snippets.

@diamond-lizard
Created November 3, 2017 19:02
Show Gist options
  • Save diamond-lizard/64bdd05e12938a3e7c0856ba805aa48e to your computer and use it in GitHub Desktop.
Save diamond-lizard/64bdd05e12938a3e7c0856ba805aa48e to your computer and use it in GitHub Desktop.
Patched w3m-form-expand-form
(el-patch-defun w3m-form-expand-form ()
"Expand the form at point so as to show the contents fully.
`w3m-show-form-hint' uses this function."
(unless (get-text-property (point) 'w3m-form-expanded)
(let ((inhibit-read-only t)
(act (w3m-action))
(mod (buffer-modified-p))
value from pt to keymap)
(when (cond ((eq (car act) 'w3m-form-input)
(setq value (w3m-form-get (nth 1 act) (nth 2 act))))
((eq (car act) 'w3m-form-input-textarea)
(setq value (w3m-form-get (nth 1 act)
(car (w3m-form-textarea-info))))))
(if (bobp)
(setq from (point))
(if (or (get-text-property (1- (point)) 'w3m-action)
(and (setq pt (previous-single-property-change
(1- (point)) 'w3m-action))
(equal (get-text-property
(setq pt (max (1- pt) (point-min))) 'w3m-action)
act)))
(while (and (not from)
(setq from (previous-single-property-change
(or pt (point)) 'w3m-action)))
(when (and (setq pt (previous-single-property-change
from 'w3m-action))
(equal (get-text-property
(max (1- pt) (point-min)) 'w3m-action)
act))
(setq from nil)))
(setq from (point))))
(setq pt nil)
(while (and (not to)
(setq to (text-property-any (or pt (point)) (point-max)
'w3m-action nil)))
(when (and (setq pt (next-single-property-change to 'w3m-action))
(equal (get-text-property pt 'w3m-action) act))
(setq to nil)))
(setq keymap (make-sparse-keymap))
(el-patch-swap
(define-key keymap "c" `(lambda nil (interactive) (kill-new ,value)))
(define-key keymap "c" `(lambda nil (interactive) (kill-new ,value)
(set-clipboard-contents ,value))))
(w3m-static-when (featurep 'emacs)
(define-key keymap [mouse-1] 'ignore)
(define-key keymap [drag-mouse-1] 'ignore))
(if (<= (length (replace-regexp-in-string "[\t\n ]+" "" value))
(length (replace-regexp-in-string
"[\t\n ]+" ""
(replace-regexp-in-string
"][\t\n ]*\\[" ""
(buffer-substring-no-properties from to)))))
(put-text-property from to 'keymap keymap)
(setq pt (cons (current-column)
(- (count-lines from (point))
(if (= from (point)) 0 1))))
(goto-char to)
(add-text-properties
from to (list 'rear-nonsticky nil 'keymap keymap))
(insert-and-inherit value)
(put-text-property to (point) 'w3m-form-expanded
(list from (- (point) (- to from))
(buffer-substring from to)))
(dolist (o (overlays-at from))
(when (= (overlay-start o) from)
(move-overlay o to (point))))
(delete-region from to)
(goto-char from)
(forward-line (cdr pt))
(move-to-column (car pt))
(deactivate-mark)
(set-buffer-modified-p mod))))))
@diamond-lizard
Copy link
Author

Note lines 40-43:

        (el-patch-swap
          (define-key keymap "c" `(lambda nil (interactive) (kill-new ,value)))
          (define-key keymap "c" `(lambda nil (interactive) (kill-new ,value)
                                    (set-clipboard-contents ,value))))

Line 41 is the original and 42-43 the new.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment