unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Tassilo Horn <tassilo@member.fsf.org>
To: Moritz Maxeiner <moritzmaxeiner@googlemail.com>
Cc: emacs-devel@gnu.org
Subject: Re: DocView AutoFitting via "doc-view-autofit-mode"
Date: Sun, 01 Apr 2012 11:34:02 +0200	[thread overview]
Message-ID: <87sjgnbxth.fsf@thinkpad.tsdh.de> (raw)
In-Reply-To: <4F764EBB.5030102@googlemail.com> (Moritz Maxeiner's message of "Sat, 31 Mar 2012 02:24:27 +0200")

Moritz Maxeiner <moritzmaxeiner@googlemail.com> writes:

Hi Moritz,

thanks for hacking on doc-view.

Here are some minor suggestions glancing at your code.

> + (defvar doc-view-autofit-mode-map
> +   (let ((map (make-sparse-keymap)))
> +     (define-key map (kbd "C-c W") 'doc-view-autofit-width)
> +     (define-key map (kbd "C-c H") 'doc-view-autofit-height)
> +     (define-key map (kbd "C-c P") 'doc-view-autofit-page)
> +     map)
> +   "Keymap used by `doc-view-autofit-mode'.")

Bindings starting with "C-c <single-char>" are usually reserved to the
user, so you should use some other binding.  Or maybe another idea was
to make the existing fitting functions accept a prefix arg activating
the autofit mode, e.g., `W' fits width once, `C-1 W' enables width
autofitting.

> + (defun doc-view-autofit-fit ()
> +   "Fits the document in the selected window's buffer
> + delayed with a timer, so multiple calls in succession
> + don't cause as much overhead."
> +   (lexical-let
> +       ((window (selected-window)))

I think doc-view doesn't rely on dynamic scoping of non-special
variables, so you could just enable lexical binding for the complete
file and use just `let'.  See (info "(elisp)Using Lexical Binding").

> +     (if (equal doc-view-autofit-timer nil)

(not doc-view-autofit-timer) would be a bit more conventional.  Or use
just `doc-view-autofit-timer' as expression and swap the branches of the
`if'.

> +         (setq doc-view-autofit-timer
> +               (run-with-timer
> +                doc-view-autofit-timer-start nil
> +                (lambda ()
> +                  (if (window-live-p window)
> +                      (save-selected-window
> +                        (select-window window)
> +                        (cancel-timer doc-view-autofit-timer)
> +                        (setq doc-view-autofit-timer nil)
> +                        (cond
> +                         ((equal 'width doc-view-autofit-type)
> +                          (doc-view-fit-width-to-window))
> +                         ((equal 'height doc-view-autofit-type)
> +                          (doc-view-fit-height-to-window))
> +                         ((equal 'page doc-view-autofit-type)
> +                          (doc-view-fit-page-to-window))))))))

Compare symbols with `eq'.  And make that lambda a named function.

> +       (timer-inc-time doc-view-autofit-timer doc-view-autofit-timer-inc))))
> +
> + (define-minor-mode doc-view-autofit-mode
> +   "Minor mode for automatic (timer based) fitting in DocView."
> +   :lighter " AFit" :keymap doc-view-autofit-mode-map :group 'doc-view
> +   (when doc-view-autofit-mode
> +     (set (make-local-variable 'doc-view-autofit-type)
> +          doc-view-autofit-default-fit)
> +     (set (make-local-variable 'doc-view-autofit-timer) nil)
> +     (add-hook 'window-configuration-change-hook
> +               'doc-view-autofit-fit nil t)
> +     (doc-view-autofit-fit))
> +   (when (not doc-view-autofit-mode)
> +     (remove-hook 'window-configuration-change-hook
> +                  'doc-view-autofit-fit t)
> +     (when doc-view-autofit-timer
> +         (cancel-timer doc-view-autofit-timer)
> +         (setq doc-view-autofit-timer nil))
> +     (setq doc-view-autofit-type nil)))

Why 2 whens instead of one if?

I didn't have time to try it out so far.  But it looks like a useful
addition, especially when using ImageMagick as backend where rescaling
doesn't trigger a reconversion.

Bye,
Tassilo



  reply	other threads:[~2012-04-01  9:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-31  0:24 DocView AutoFitting via "doc-view-autofit-mode" Moritz Maxeiner
2012-04-01  9:34 ` Tassilo Horn [this message]
2012-04-02 17:58   ` Moritz Maxeiner
2012-04-02 18:37     ` Drew Adams
2012-04-02 18:41     ` Tassilo Horn
2012-04-03 13:34     ` Stefan Monnier
2012-04-03 13:38       ` Moritz Maxeiner
2012-04-03 14:51         ` Stefan Monnier
2012-04-03 15:11           ` Moritz Maxeiner
2012-04-03 16:14             ` Stefan Monnier
2012-04-26  3:19               ` Stefan Monnier
2012-04-03 15:18           ` Tassilo Horn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sjgnbxth.fsf@thinkpad.tsdh.de \
    --to=tassilo@member.fsf.org \
    --cc=emacs-devel@gnu.org \
    --cc=moritzmaxeiner@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).