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

w3m improvement for local files



Dear Bug Team!
Sorry , I've not found an other email-Address so I am using this one.
If I am using W3M to browse on the local filesystem, eg. some documentation
then its better to use emacs-built-in-Modes for some Filetyes (C,shell, ...)
so I have made my local improvents. see attachment ~/elisp/21.3/w3m-wjc.el

Wolfgang Clesle

===File ~/elisp/21.3/w3m-wjc.el==================
;override w3m-view-this-url for local existing files to use emacs directly
(defvar w3m-ori-emacs-regexp
  (eval-when-compile
    (concat "\\<"
            (regexp-opt
          '("c" "c++" "cpp" "h" "idl" "txt") t)
         "\\>"))
  "regexp for matching files-extensions for using emacs instead of w3m")

(defvar w3m-not-emacs-regexp
  (eval-when-compile
    (concat "\\<"
            (regexp-opt
          '("gif" "jpeg" "ps" "pdf" "html" "mpeg") t)
         "\\>"))
  "regexp for matching files-extensions not using emacs ")

(defun w3m-view-this-url-old (&optional arg new-session)
  "View the URL of the link under point.  If ARG is the number 2 or the
list of the number 16 (you may produce this by typing `C-u' twice) or
NEW-SESSION is non-nil, and the link is an anchor, make a copy of the
current session in advance.  Otherwise, if ARG is non-nil, force
reload the url at point.  If the option `w3m-pop-up-frames' is non-nil,
also make a new frame for the copied session."
  (interactive (if (member current-prefix-arg '(2 (16)))
             (list nil t)
           (list current-prefix-arg nil)))
  (let ((url (w3m-anchor))
     (act (w3m-action))
     local-filename
     )
    (cond
     (act (eval act))
     (url
      (if (string-match "file:///" url) ;local file
       (progn
         (setq local-filename (substring url (length "file://")))
         (or (and
           (or (file-directory-p local-filename)
               (string-match w3m-ori-emacs-regexp (file-name-extension
local-filename))
               (not (string-match w3m-not-emacs-regexp (file-name-extension
local-filename))))
           (if (y-or-n-p (format "use emacs for file %s" url))
               (find-file-other-window local-filename)))
          (w3m-view-this-url-1 url arg new-session)))
     (w3m-view-this-url-1 url arg new-session)))
      ((w3m-image)
      (if (w3m-display-graphic-p)
       (w3m-toggle-inline-image)
     (w3m-view-image)))
     ((setq url (w3m-url-at-point))
      (unless (eq 'quit (setq url (w3m-input-url nil url 'quit)))
     (w3m-view-this-url-1 url arg new-session)))
     (t (w3m-display-message "No URL at point")))))


(defun w3m-view-this-url (&optional arg new-session)
  "View the URL of the link under point.  If ARG is the number 2 or the
list of the number 16 (you may produce this by typing `C-u' twice) or
NEW-SESSION is non-nil, and the link is an anchor, make a copy of the
current session in advance.  Otherwise, if ARG is non-nil, force
reload the url at point.  If the option `w3m-pop-up-frames' is non-nil,
also make a new frame for the copied session."
  (interactive (if (member current-prefix-arg '(2 (16)))
             (list nil t)
           (list current-prefix-arg nil)))
  (let ((url (w3m-anchor))
     (act (w3m-action))
     local-filename
     )
    (cond
     (act (eval act))
     (url
      (if (string-match "file:///" url) ;local file
       (progn
         (setq local-filename (substring url (length "file://")))
         (or
          (and (file-directory-p local-filename)
            (if (y-or-n-p (format "use emacs for file %s" url))
                (find-file-other-window local-filename)))
          (and (not (file-name-extension local-filename)) ; file with no
extension
            (if (y-or-n-p (format "use emacs for file %s" url))
               (find-file-other-window local-filename)))
          (and (string-match w3m-ori-emacs-regexp (file-name-extension
local-filename))
            (find-file-other-window local-filename))
          (and (string-match w3m-not-emacs-regexp (file-name-extension
local-filename))
            (progn
              (w3m-view-this-url-1 url arg new-session)
              t ))
          (if (y-or-n-p (format "use emacs for file %s" url))
               (find-file-other-window local-filename))
          (w3m-view-this-url-1 url arg new-session)
         ))
     (w3m-view-this-url-1 url arg new-session)))
      ((w3m-image)
      (if (w3m-display-graphic-p)
       (w3m-toggle-inline-image)
     (w3m-view-image)))
     ((setq url (w3m-url-at-point))
      (unless (eq 'quit (setq url (w3m-input-url nil url 'quit)))
     (w3m-view-this-url-1 url arg new-session)))
     (t (w3m-display-message "No URL at point")))))
============================================================