all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: joaotavora@gmail.com (João Távora)
To: Rasmus <rasmus@gmx.us>
Cc: emacs-devel@gnu.org
Subject: Re: [mentoring] a darkroom/writeroom mode for Emacs
Date: Thu, 11 Dec 2014 11:22:37 +0000	[thread overview]
Message-ID: <m2h9x24eiq.fsf@king.lan> (raw)
In-Reply-To: <87bnnczcjg.fsf@gmx.us> (rasmus@gmx.us's message of "Tue, 09 Dec 2014 23:25:07 +0100")

Rasmus <rasmus@gmx.us> writes:

>> ;; Copyright (C) 2014  João Távora
> There's usually a clause somewhere about whether it's part of Emacs.  It's
> probably not important.

That's what M-x auto-insert gave me. I should assign it to the FSF
though.

> This paragraph is not clear and potentially tautologous.

The opening tautology is necessary to diffentiate it from
`darkroom-tentative-mode'. I wonder what else is not clear, but I have
rewritten it.

> You might want to mention the function you wrote below.  Maybe it should
> be default if you can sort out the FIXME

Yes, I had that in mind.

>> Value is effective when `darkroom-mode' is toggled, when
>> changing window or by calling `darkroom-set-margins'"
>>   :type 'float
>>   :group 'darkroom)
> So, there's both a function to calculate margins the possibility of
> specifying it manually?  What takes priority?

You found a bug, that second part of the docstring no longer applies.

>> (defun darkroom-guess-margins ()
>>   "Guess suitable margins for `darkroom-margins'.
> I think there should be a blank line here.

I don't think Emacs uses that particular blank, but OK.

>> Collects some statistics about the buffer's line lengths, and
>> apply a heuristic to figure out how wide to set the margins. If
>> the buffer's paragraphs are mostly filled to `fill-column',
>> margins should center it on the window, otherwise, margins of
>> 0.15 percent are used."

> Why the need for hardcoding?

To make time for southpark. Also it's cold, typing hurts and naming
variables is hard. I've fixed it.

>>   ;;; FIXME: broken when darkroom-text-scale-increase is anything but
>>   ;;; 0, since window-width ignores text scaling. Otherwise, a
>>   ;;; suitable default to put in `darkroom-margins', I guess.
>
> You can estimate the realized width rolling over some lines and measure.
> Probably there's a more appropriate way of doing it.  
>
> (save-excursion (- (progn (end-of-visual-line) (point))
>                    (progn (beginning-of-visual-line) (point))))
>
> Note, for understanding this you might get some insights from studying
> `line-move' and `line-move-visual' (I don't know).

It helped. I dealt with the FIXME with the ultra-horrible
`darkroom--real-window-width'. It fixes `window-width' basically. Seems
to work. The above won't work because I need to know about window
geometry, not line geometry. Unless there's a very big line. And that's
how `darkroom--real-window-width' hacks it.

>>     (let* ((window-width (window-width))
>>            (line-widths (save-excursion
> I'm not sure this does what you want.  A quick test suggests it will find
> the end of the line, not the "visual" end of the line.

Yes, but I want to collect actual line widths here. 

> You do you need to add this to the top of your file?
>
>     (eval-when-compile (require 'cl))

I don't think I need it. I use no compile-time cl-functions.

> This seems like overenginering.  What about something like this (not
> tested, check that it works out with the floats).

> (let ((n4 (/ (length n) 4)))
>      (/ (apply '+ (subseq (sort line-width '>) 0 n4)) n4))

Cleaner, needs cl-subseq..

>>                    "Perhaps turn on visual-line-mode for a better darkroom?")
>>                  "\n")
> Here you can use concat and format. . .  In general this functionally
> seems a bit obstructive.  "Dont's ask me stuff..."

OK removed it and replaced with a message.

>
>>                 top-quartile-avg window-width))
>>           (visual-line-mode 1))
>>         0.15)
>>        ((> top-quartile-avg (* 0.9 fill-column))
>>         (let ((margin (round (/ (- window-width top-quartile-avg) 2))))
>>           (cons margin margin)))
>>        (t
>>         0.15)))))
>
> I think you can simplify this and you should not hardcode .15.

Ideas welcome, I didn't think much about the heuristic, this one worked
ok. I fixed the hardcoding.

>> (defun darkroom-compute-margins ()
> docstring, please.  What's the *idea* of this function.

It's an internal function (what version of code were you looking
at). It, well, computes margins. This is a big discusison, but while I
very much sympathise with your thoroughness in documentation, docstrings
should explain the "what" carefully avoiding the "how", so you can
change that later. For internal functions, it might be a good idea to
leave them out, rather than risk them getting out of date, or hindering
others from redesigning your code. I know this from experience. Anyway,
to please my mentor, I added a docstring :-)

>> (defun darkroom-float-to-columns (f)
>>   (ceiling (* (let ((edges (window-edges)))
>>                 (- (nth 2 edges) (nth 0 edges)))
>>               f)))
>
> (- (line-end-position) (line-beginning-position))

No. Here I'm concerned with the window geometry, not the current line's
geometry.

>> (defvar darkroom-buffer-margins nil
>>   "Buffer-local version of `darkroom-margins' defcustom.
>> Set by `darkroom-set-margins'")
>
> I think these should all be at the top of the file.

I prefer nearer the users. Unless the file gets big and demands a
particular structure, in which case I try to first separate by
functionality, not programming construct.

>>     (walk-windows #'(lambda (w)
>>                       (when (eq (window-buffer w) (current-buffer))
>>                   'all-frames)))
>
> Can't you use with-current-buffer?  The walk-windows seems excessive.

Keep in mind I need to affect all windows that display that buffer. There
might be several.

> You should test this when resizing windows and increasing fonts. . .

You're right. I'll do that before I submit. Did you test it?

>>   (setcdr darkroom-buffer-margins
>>           (round (* (+ 1 increment) (cdr darkroom-buffer-margins))))
>       (setq  darkroom-buffer-margins (cons · ·))

I could, but there's no big benefit and this also make the consness
explicit.

>> (defun darkroom-decrease-margins (decrement)
> docstring

You either weren't looking at the latest version, or I didn't push it.

>>   (let ((map (make-sparse-keymap)))
>>     (define-key map (kbd "C-M-+") 'darkroom-increase-margins)
>>     (define-key map (kbd "C-M--") 'darkroom-decrease-margins)
>>     map))
>
> Ideally this should be unnecessary.  Maybe it should be called after
> changing the font size or whatnot.

Well, the user might want to tweak it for some reason. But yes,
`darkroom--set-margins' should be called from more hooks.

>> (defvar darkroom-saved-mode-line-format nil)
>> (defvar darkroom-saved-header-line-format nil)
>> (defvar darkroom-saved-margins nil)
>
> Top of file.  And docstring.

Docstring done.

>>         (t
>>          (setq mode-line-format darkroom-saved-mode-line-format
>>                header-line-format darkroom-saved-header-line-format)
>>          (text-scale-decrease darkroom-text-scale-increase)
>
> You need to actually record the size used before the mode is entered.  I
> could increase the width after I enter darkroom.

I started to implement this, then realized, maybe it needn't be so,
because it works by increments. Did you try it?

>>         (t
>>          ;; (message "debug: buffer: %s windows: %s darkroom-mode: %s"
>>          ;;          (current-buffer) (count-windows) darkroom-mode)
>>          )))
>
> You don't need the last clause.  Also, do you want to test if
> (eq major-mode 'darkroom-mode) ?

Keep it there for future debugging. I don't understand. `darkroom-mode'
is a minor mode.

> Some comments follow.  I did it quickly (as you may notice), but it still
> took 1½ South Park episodes.

Which ones are you watching?

João



  reply	other threads:[~2014-12-11 11:22 UTC|newest]

Thread overview: 249+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20141203142859.24393.98673@vcs.savannah.gnu.org>
     [not found] ` <E1XwAvL-0006M3-CA@vcs.savannah.gnu.org>
2014-12-03 15:31   ` [Emacs-diffs] master e820f16: Added file-tree-walk to files.el Stefan Monnier
2014-12-03 19:31     ` Eric S. Raymond
2014-12-03 21:19       ` Stefan Monnier
2014-12-03 21:54         ` Metaproblem, part 3 Eric S. Raymond
2014-12-03 22:13           ` Stefan Monnier
2014-12-04  6:30           ` Eli Zaretskii
2014-12-04  6:32           ` Paul Eggert
2014-12-04 15:37             ` Stefan Monnier
2014-12-04 16:06               ` Lars Magne Ingebrigtsen
2014-12-04 17:53                 ` Stefan Monnier
2014-12-04 21:48                   ` Lars Magne Ingebrigtsen
2014-12-04 22:53                   ` Paul Eggert
2014-12-05  4:40                     ` Stefan Monnier
2014-12-05  7:20                       ` Stephen J. Turnbull
2014-12-05  8:06                       ` Glenn Morris
2014-12-05 11:24                         ` andres.ramirez
2014-12-05 14:26                       ` Stefan Monnier
2014-12-05 14:46                         ` David Kastrup
2014-12-05 14:47                       ` Lars Magne Ingebrigtsen
2014-12-05 18:38                         ` Stefan Monnier
2014-12-06 17:29                           ` Lars Magne Ingebrigtsen
2014-12-06 18:05                             ` Lars Magne Ingebrigtsen
2014-12-13 22:03                       ` Alan Mackenzie
2014-12-04 15:40             ` Generate ChangeLogs (was: Metaproblem, part 3) Lars Magne Ingebrigtsen
2014-12-04 17:23               ` Generate ChangeLogs Karl Fogel
2014-12-04 17:28                 ` Eric S. Raymond
2014-12-04 17:40               ` Paul Eggert
2014-12-04 19:09                 ` Achim Gratz
2014-12-05  8:07                 ` Glenn Morris
2014-12-06  2:24                   ` Paul Eggert
2014-12-04 18:18               ` Ted Zlatanov
2014-12-04 13:58           ` Metaproblem, part 3 Phillip Lord
2014-12-04 14:32             ` João Távora
2014-12-04 17:40               ` Eli Zaretskii
2014-12-05 10:27                 ` João Távora
2014-12-05 10:45                   ` Eli Zaretskii
2014-12-05 11:21                     ` João Távora
2014-12-05 11:31                       ` Eli Zaretskii
2014-12-05 12:20                         ` João Távora
2014-12-05 13:16                           ` Kelvin White
2014-12-05 14:52                           ` Eli Zaretskii
2014-12-06  5:38                             ` Stephen J. Turnbull
2014-12-06  7:07                               ` João Távora
2014-12-06  8:03                                 ` Eli Zaretskii
2014-12-08 11:40                                   ` [mentor-request] a darkroom/writeroom mode for Emacs João Távora
2014-12-08 12:15                                     ` joakim
2014-12-09 11:46                                       ` João Távora
2014-12-09 12:45                                         ` joakim
2014-12-10  2:39                                         ` Stephen J. Turnbull
2014-12-08 12:40                                     ` Rasmus
2014-12-09 11:28                                       ` [mentoring] " João Távora
2014-12-09 12:20                                         ` Rasmus
2014-12-09 13:11                                           ` João Távora
2014-12-09 14:56                                             ` Rasmus
2014-12-10  0:54                                               ` Stefan Monnier
2014-12-10  1:22                                                 ` Rasmus
2014-12-09 22:25                                             ` Rasmus
2014-12-11 11:22                                               ` João Távora [this message]
2014-12-11 17:15                                                 ` Stefan Monnier
2014-12-12 11:19                                                   ` João Távora
2014-12-11 18:33                                                 ` Rasmus
2014-12-12 11:16                                                   ` João Távora
2014-12-12 12:09                                                     ` Rasmus
2014-12-15 12:01                                                       ` [mentoring-done] " João Távora
2014-12-15 13:06                                                         ` Dmitry Gutov
2014-12-15 13:20                                                           ` João Távora
2014-12-15 13:47                                                             ` Dmitry Gutov
2014-12-15 13:55                                                               ` João Távora
2014-12-15 14:38                                                             ` Stefan Monnier
2014-12-15 13:19                                                         ` martin rudalics
2014-12-15 13:37                                                           ` João Távora
2014-12-15 14:15                                                             ` martin rudalics
2014-12-15 14:54                                                               ` João Távora
2014-12-15 15:28                                                                 ` martin rudalics
2014-12-15 22:10                                                                   ` João Távora
2014-12-12 14:27                                                     ` [mentoring] " Drew Adams
2014-12-12 14:38                                                     ` Stefan Monnier
2014-12-09 16:32                                         ` Phillip Lord
2014-12-08 11:46                                   ` [mentor-request] Ecco - a literate programming documentation generator João Távora
2014-12-21 20:17                                   ` Results of the "mentoring" experiment Re: Metaproblem, part 3 João Távora
2014-12-21 21:22                                     ` Rasmus
2014-12-22 14:14                                     ` Results of the "mentoring" experiment Stephen Leake
2014-12-22 16:01                                       ` João Távora
2014-12-22 16:03                                       ` João Távora
2014-12-05 12:16                       ` Metaproblem, part 3 Phillip Lord
2014-12-05 13:20                     ` Eric Abrahamsen
2014-12-05 14:59                       ` Eli Zaretskii
2014-12-06  5:45                       ` Stephen J. Turnbull
2014-12-06  6:18                         ` Eric S. Raymond
2014-12-06  8:01                           ` Eli Zaretskii
2014-12-06 16:32                           ` Stephen J. Turnbull
2014-12-06  8:29                         ` Eric Abrahamsen
2014-12-06 10:11                           ` Eli Zaretskii
2014-12-06 10:40                             ` Eric Abrahamsen
2014-12-06 10:47                               ` Eli Zaretskii
2014-12-06 11:04                           ` David Kastrup
2014-12-06 12:52                             ` Ivan Shmakov
2014-12-07  1:41                             ` Eric Abrahamsen
2014-12-09 12:29                               ` João Távora
2014-12-06 14:18                           ` Stephen J. Turnbull
2014-12-07  1:38                             ` Eric Abrahamsen
2014-12-06 10:51                         ` David Kastrup
2014-12-07  9:19                           ` Richard Stallman
2014-12-05 10:56                 ` Phillip Lord
2014-12-05 11:15                   ` Eli Zaretskii
2014-12-05 12:09                     ` Phillip Lord
2014-12-05 14:50                       ` Eli Zaretskii
2014-12-03 19:32     ` [Emacs-diffs] master e820f16: Added file-tree-walk to files.el David Engster
2014-12-03 19:53       ` Eric S. Raymond
2014-12-03 19:58         ` David Engster
2014-12-03 20:08           ` Eric S. Raymond
2014-12-03 20:28             ` David Engster
2014-12-03 20:58               ` Eric S. Raymond
2014-12-04 20:28                 ` David Engster
2014-12-04 20:46                   ` Eli Zaretskii
2014-12-05  2:16                   ` Stefan Monnier
2014-12-05  8:06                     ` Glenn Morris
2014-12-03 15:34   ` Stefan Monnier
2014-12-03 16:41     ` Thien-Thi Nguyen
2014-12-03 18:08       ` Eli Zaretskii
2014-12-03 18:36         ` Tom
2014-12-03 19:21           ` Paul Eggert
2014-12-03 19:27             ` Tom
2014-12-03 18:58         ` Lars Magne Ingebrigtsen
2014-12-03 19:26           ` Eric S. Raymond
2014-12-03 19:11         ` Thien-Thi Nguyen
2014-12-03 19:27     ` Eric S. Raymond
2014-12-03 19:41       ` Paul Eggert
2014-12-03 20:03         ` Commit comment rules - and a metaproblem Eric S. Raymond
2014-12-03 20:26         ` [Emacs-diffs] master e820f16: Added file-tree-walk to files.el Eli Zaretskii
2014-12-03 21:14           ` More metaproblem Eric S. Raymond
2014-12-03 22:13             ` Karl Fogel
2014-12-04  6:38               ` Eli Zaretskii
2014-12-04  8:38                 ` Stephen Leake
2014-12-04 10:11                   ` Eli Zaretskii
2014-12-04 10:23                   ` David Kastrup
2014-12-04 15:35                   ` Stefan Monnier
2014-12-04 16:33                     ` Stephen Leake
2014-12-04 17:37                     ` Eli Zaretskii
2014-12-04 20:43                       ` Stefan Monnier
2014-12-04 21:26                         ` Eli Zaretskii
2014-12-05 23:03                     ` chad
2014-12-04  9:08                 ` Stephen Leake
2014-12-04 10:01                   ` Eli Zaretskii
2014-12-04 10:11                     ` David Kastrup
2014-12-04 10:27                     ` Eric S. Raymond
2014-12-04 10:35                       ` David Kastrup
2014-12-04 11:01                         ` Eli Zaretskii
2014-12-04 11:07                           ` Eric S. Raymond
2014-12-05  1:23                       ` Stephen J. Turnbull
2014-12-05  6:53                         ` Eli Zaretskii
2014-12-04 18:33                 ` Karl Fogel
2014-12-04 21:21                   ` Eli Zaretskii
2014-12-04 22:01                     ` Jorgen Schaefer
2014-12-05  7:08                       ` Eli Zaretskii
2014-12-05  7:55                         ` Aurélien Aptel
2014-12-05  8:44                           ` Eli Zaretskii
2014-12-06 10:41                           ` the Emacs wiki Stephen Leake
2014-12-06 10:58                             ` Eli Zaretskii
2014-12-06 21:28                             ` Nic Ferrier
2014-12-07 22:47                               ` Stephen Leake
2014-12-09  8:04                                 ` Nic Ferrier
2014-12-09 22:28                                   ` Alexis
2014-12-10 21:32                                     ` Nic Ferrier
2014-12-06  5:11                         ` More metaproblem Stephen J. Turnbull
2014-12-06  7:47                           ` Eli Zaretskii
2014-12-05 11:52                       ` Nicolas Richard
2014-12-05 22:43                         ` Richard Stallman
2014-12-05 16:51                     ` Karl Fogel
2014-12-05 16:57                       ` Lars Magne Ingebrigtsen
2014-12-05 18:24                         ` Eric S. Raymond
2014-12-05 21:16                           ` Karl Fogel
2014-12-05 18:56                         ` Stefan Monnier
2014-12-05 17:27                       ` Eli Zaretskii
2014-12-05 17:52                         ` Karl Fogel
2014-12-05 18:39                           ` Glenn Morris
2014-12-05 21:23                             ` Karl Fogel
2014-12-05 22:24                               ` Eric S. Raymond
2014-12-05 22:41                                 ` Ted Zlatanov
2014-12-05 23:02                                   ` Eli Zaretskii
2014-12-05 23:12                                 ` Eli Zaretskii
2014-12-06  4:58                                   ` Eric S. Raymond
2014-12-06  7:42                                     ` Eli Zaretskii
2014-12-06 11:35                                       ` Eric S. Raymond
2014-12-06 11:58                                         ` David Kastrup
2014-12-06 12:35                                         ` Eli Zaretskii
2014-12-06 14:10                                           ` Werner LEMBERG
2014-12-06  9:27                           ` Stephen Leake
2014-12-06 10:20                             ` Eli Zaretskii
2014-12-06 11:41                             ` Eric S. Raymond
2014-12-06 12:37                               ` Eli Zaretskii
2014-12-06 13:16                                 ` David Kastrup
2014-12-06 14:22                                   ` Eli Zaretskii
2014-12-05 18:19                       ` Eric S. Raymond
2014-12-05 21:14                         ` Karl Fogel
2014-12-05 21:23                           ` Eric S. Raymond
2014-12-05 18:20                       ` Glenn Morris
2014-12-05 18:56                         ` Eric S. Raymond
2014-12-05 20:11                           ` Eli Zaretskii
2014-12-08 17:16                             ` Glenn Morris
2014-12-09 11:00                               ` Richard Stallman
2014-12-06  9:41                           ` Stephen Leake
2014-12-06  9:10                       ` maintaining FSF Emacs web page Stephen Leake
2014-12-06 17:57                         ` Karl Fogel
2014-12-07  9:20                         ` Richard Stallman
2014-12-09 12:30                           ` Alex Schroeder
2014-12-10  8:24                             ` Richard Stallman
2014-12-06  9:19                       ` More metaproblem Stephen Leake
2014-12-06 16:44                         ` Drew Adams
2014-12-06 18:41                           ` Stephen Leake
2014-12-06 19:24                             ` Drew Adams
2014-12-07 22:07                               ` Stephen Leake
2014-12-07 23:00                                 ` Drew Adams
2014-12-08 15:57                                   ` Eli Zaretskii
2014-12-08 21:23                                 ` Przemysław Wojnowski
2014-12-09 16:54                                   ` Eli Zaretskii
2014-12-10  9:16                                     ` Stephen Leake
2014-12-10 19:46                                     ` Przemysław Wojnowski
2014-12-10 20:48                                       ` Eli Zaretskii
2014-12-10 22:10                                         ` Stefan Monnier
2014-12-10 20:09                                   ` Przemysław Wojnowski
2014-12-10 20:28                                     ` Stefan Monnier
2014-12-05  9:58                   ` Stephen Leake
2014-12-05 15:44                     ` Stefan Monnier
2014-12-05 17:37                       ` Karl Fogel
2014-12-05 19:36                         ` Stefan Monnier
2014-12-05 17:34                     ` Karl Fogel
2014-12-05 17:40                       ` Lars Magne Ingebrigtsen
2014-12-05 17:54                         ` Karl Fogel
2014-12-06 12:04                         ` Richard Stallman
2014-12-06 18:56                           ` publicizing Emacs contribute Stephen Leake
2014-12-06 19:29                             ` Óscar Fuentes
2014-12-07  1:00                               ` Dmitry Gutov
2014-12-07  1:33                                 ` Óscar Fuentes
2014-12-08  0:23                               ` Richard Stallman
2014-12-07  9:21                             ` Richard Stallman
2014-12-07 23:06                               ` Stephen Leake
2014-12-05 18:04                       ` More metaproblem Eric S. Raymond
2014-12-06 10:19                       ` Stephen Leake
2014-12-05 11:45                   ` Phillip Lord
2014-12-06  5:17                     ` Stephen J. Turnbull
2014-12-06 10:17                       ` David Kastrup
2014-12-06 16:45                         ` Drew Adams
2014-12-06 10:30                       ` Stephen Leake
2014-12-03 22:14             ` Stefan Monnier
2014-12-04  3:32             ` Stephen Leake
2014-12-04  6:25             ` Eli Zaretskii
2014-12-05 18:37   ` master e820f16: Added file-tree-walk to files.el Michael Heerdegen
2014-12-05 18:57     ` Eric S. Raymond

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

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

  git send-email \
    --in-reply-to=m2h9x24eiq.fsf@king.lan \
    --to=joaotavora@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=rasmus@gmx.us \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.