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

toggle-filter-state function (patch included)



Greetings all,

If y'all feel the function below would be of general use, I'd be
honored for it to be included in the package. It's easier than
manually toggling `w3m-use-filter' and it's much much easier than
manually toggling a single filter.

A word about binding it to a logical key. Both 'f' and 'F' are already
bound by the `w3m-lnum-mode', but each of those keybindings are
redundant (to `L-f' and `L-F', respectively). I suggest keeping the
w3m-lnum functions bound to the single key combinations `L-f', `L-F',
and free up 'f', 'F' for this function and some future one.

Regards.


(defun w3m-toggle-filtering (arg)
"Toggle whether web pages will have their html modified by w3m's
 filters before being rendered.

 When called with the universal argument, prompts for a single filter
 to toggle, and supplies in the minibuffer history a scrollable /
 searchable list of existing filters."

  (interactive "P")
  (setq templist nil)
  (if (not arg)
    ; toggle state for all filters
    (progn
      (setq w3m-use-filter (not w3m-use-filter))
      (message (concat
        "web page filtering now "
        (if w3m-use-filter "enabled" "disabled"))))
   ; the remainder of this function if for the case of toggling an
   ; individual filter
   (let (elem atom w3m-filter-selection-list)
     ; update w3m-filter-selection-list
     (dolist (elem w3m-filter-configuration)
       (let* (
         (atom (nth 0 (last elem)))
         (atom (if (listp atom) (nth 0 atom) atom))
         (atom (prin1-to-string atom)))
        (when (not (member atom w3m-filter-selection-list))
          (push atom w3m-filter-selection-list))))
     (let (
       (choice (read-from-minibuffer
         "Enter filter name (or choose by scrolling):" nil nil nil
         '(w3m-filter-selection-list . 1))))
      (when (and (boundp 'choice) (not (string= "" choice)))
        (unless
          (catch 'found
            (dolist (elem w3m-filter-configuration)
              (let* (
                (atom (nth 0 (last elem)))
                (atom (if (listp atom) (nth 0 atom) atom)))
               (when (equal choice (prin1-to-string atom))
                 (setq w3m-filter-configuration
                   (delq elem w3m-filter-configuration))
                 (if (pop elem)
                   (progn
                     (push nil elem)
                     (push elem w3m-filter-configuration))
                  (setq w3m-use-filter t)
                  (push t elem)
                  (push elem w3m-filter-configuration))
                 (message (concat "filter `" choice "' now "
                   (if (car elem) "enabled" "disabled")))
                 (throw 'found t)))))
         (message (concat "filter `" choice "' not found"))))))))

(define-key w3m-lnum-mode-map (kbd "f") nil)
(define-key w3m-mode-map (kbd "f") 'w3m-toggle-filtering)

--

--
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1  7286 0036 9E45 1595 8BC0