[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: saving a buffer without images
On 2016-09-07 14:56, Katsumi Yamaoka wrote:
> In [emacs-w3m : No.12597]
> On Tue, 06 Sep 2016 23:48:26 -0400, Boruch Baum wrote:
> >> The docstring should mention what it is in one line:
...
> ,---- (info "(elisp)Documentation Tips")
> | • The first line of the documentation string should consist of one or
> | two complete sentences that stand on their own as a summary. ‘M-x
> | apropos’ displays just the first line, and if that line’s contents
> | don’t stand on their own, the result looks bad.
> `----
OK. How's this?:
(defcustom w3m-save-buffer-html-only nil
"Save images along with a web-page, or just html.
If nil, `w3m-save-buffer' will save the images of a buffer in
addition to the buffer's html. If the buffer was originally
loaded without images, the images will now be retrieved. The
value of this variable may be over-ridden at run-time by passing
a prefix argument to function `w3m-save-buffer'."
:group 'w3m
:type 'boolean)
(defun w3m-save-buffer (name &optional no-images)
"Save the current w3m buffer.
Save the current buffer as `w3m-save-buffer-directory'/NAME.html,
and optionally save the buffer's associated image files in
folder `w3m-save-buffer-directory'/NAME-files/. Use of
`w3m-save-buffer-directory' may be over-ridden by including a
folder path in NAME. Variable `w3m-save-buffer-html-only'
determines whether images will be saved by default, but that
setting may be toggled using the prefix argument (the
optional NO-IMAGES). The saved page will be added to the
history list, and be viewable using `w3m-next-page'."
...
> >> BTW, there seems to be another way to achieve your personal
> >> purpose in a simple way, e.g.:
>
> > You alternative wasn't viewable in my email, but if it does the job
> > and you prefer it, it's fine with me.
>
> --8<---------------cut here---------------start------------->8---
> (defvar my-w3m-save-buffer-html-only nil
> "docstring")
>
> (defadvice w3m-save-buffer (around switch-no-image-flag
> (name &optional no-image)
> activate)
> "Complement the meaning of NO-IMAGE flag; don't modify history."
> (if my-w3m-save-buffer-html-only
> (setq no-image (not no-image)))
> (let ((history (copy-sequence w3m-history)))
> (unwind-protect
> ad-do-it
> (setq w3m-history history))))
> --8<---------------cut here---------------end--------------->8---
>
I wouldn't do it that way, but you certainly know the codebase better.
My reason is that I understood defadvice to be a tool to use by person
B to alter person A's function without redefining it, thus keeping the
function's orignal code for other users or other purposes. If that's
correct, then it's not the tool for you, since you are the developer
who is updating your own function. I suspect that it's also much less
efficient, if that ever is an issue.
--
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0