[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 9674d79 20/26: Fix automatic margin calculation
From: |
João Távora |
Subject: |
[elpa] master 9674d79 20/26: Fix automatic margin calculation |
Date: |
Fri, 19 Dec 2014 19:07:30 +0000 |
branch: master
commit 9674d79c185e40cdadf9f355f39530b738e94b66
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Fix automatic margin calculation
* darkroom.el (darkroom--real-window-width): Removed horrible hack.
(darkroom-guess-margins): Calculate with pixel widths.
---
darkroom.el | 64 ++++++++++++++++++++++++-----------------------------------
1 files changed, 26 insertions(+), 38 deletions(-)
diff --git a/darkroom.el b/darkroom.el
index 3973513..aa526bb 100644
--- a/darkroom.el
+++ b/darkroom.el
@@ -98,31 +98,6 @@ symmetical margins."
:type 'float
:group 'darkroom)
-(defun darkroom--real-window-width ()
- "Horrible hack to get the window width in characters.
-`window-width' ignores text scaling."
- (let ((inhibit-read-only t)
- (buffer-undo-list t)
- (truncate-lines nil)
- (truncate-partial-width-windows nil)
- (word-wrap t)
- (line-move-visual t))
- (save-excursion
- (with-silent-modifications
- (let ((begin (point)))
- (unwind-protect
- (progn
- (insert (make-string 10000 ?!))
- (save-excursion
- (goto-char begin)
- (next-line)
- (backward-char)
- (let ((margins (window-margins)))
- (+ (or (car margins) 0)
- (or (cdr margins) 0)
- (current-column)))))
- (delete-region begin (point))))))))
-
(defvar darkroom--guess-margins-statistics-cache nil
"Cache used by `darkroom-guess-margins'.")
@@ -138,25 +113,38 @@ which is a width in columns, in which case it will be used
instead of a window's geometry."
(if visual-line-mode
darkroom-margins-if-failed-guess
- (let* ((window-width (if (integerp window)
+ (let* ((char-width (car (window-text-pixel-size
+ (selected-window)
+ (point-min) (1+ (point-min)))))
+ (window-width (if (integerp window)
window
(with-selected-window window
- ;; (let ((edges (window-edges)))
- ;; (- (nth 2 edges) (nth 0 edges)))
- (darkroom--real-window-width))))
+ (let ((saved (window-margins)))
+ (set-window-margins window 0 0)
+ (prog1 (truncate
+ (window-width window 'pixelwise)
+ char-width)
+ (set-window-margins window (car saved)
+ (cdr saved)))))))
(top-quartile-avg
(or darkroom--guess-margins-statistics-cache
(set
(make-local-variable
'darkroom--guess-margins-statistics-cache)
- (let* ((line-widths (save-excursion
- (goto-char (point-min))
- (cl-loop for start = (point)
- while (search-forward "\n"
- 20000
-
'no-error)
- for width = (- (point) start 1)
- unless (zerop width)
- collect width)))
+ (let* ((line-widths
+ (save-excursion
+ (goto-char (point-min))
+ (cl-loop for start = (point)
+ while (search-forward "\n"
+ 20000
+ 'no-error)
+ for width = (truncate
+ (car
+ (window-text-pixel-size
+ window
+ start (1- (point))))
+ char-width)
+ unless (zerop width)
+ collect width)))
(n4 (max 1 (/ (length line-widths) 4))))
(/ (apply '+ (cl-subseq (sort line-widths '>) 0 n4))
n4))))))
(cond
- [elpa] master a16a665 01/26: Initial commit, (continued)
- [elpa] master a16a665 01/26: Initial commit, João Távora, 2014/12/19
- [elpa] master 3a1db96 13/26: Add some docstrings, João Távora, 2014/12/19
- [elpa] master a39ab2e 15/26: Minor tweaks, João Távora, 2014/12/19
- [elpa] master 90f5299 14/26: Prefix internal symbols with "darkroom--", João Távora, 2014/12/19
- [elpa] master 8b0daf6 12/26: Add (still non-functioning) `darkroom-compute-margins', João Távora, 2014/12/19
- [elpa] master 13717fb 17/26: Attempt a clearer design of modes, João Távora, 2014/12/19
- [elpa] master 20d5539 21/26: load cl-lib, João Távora, 2014/12/19
- [elpa] master 4bf9c10 19/26: Fix `darkroom-tentative-mode', João Távora, 2014/12/19
- [elpa] master 1e68955 16/26: Corrections after another review iteration with Rasmus, João Távora, 2014/12/19
- [elpa] master 15e976b 22/26: Merge pull request #1 from syohex/require-cl-lib, João Távora, 2014/12/19
- [elpa] master 9674d79 20/26: Fix automatic margin calculation,
João Távora <=
- [elpa] master 2887b5e 18/26: Redesign setting of margins, which now works per-window, João Távora, 2014/12/19
- [elpa] master 96e61a9 26/26: Add packages/darkroom by merging its upstream subtree, João Távora, 2014/12/19
- [elpa] master 5de9a5d 24/26: Fix darkroom-tentative-mode when switching window's buffer, João Távora, 2014/12/19
- [elpa] master 654e5fd 23/26: Fix margin calculation yet again., João Távora, 2014/12/19
- [elpa] master 7a8b5b6 25/26: Prepare for inclusion in GNU ELPA, João Távora, 2014/12/19