[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master a16a665 01/26: Initial commit
From: |
João Távora |
Subject: |
[elpa] master a16a665 01/26: Initial commit |
Date: |
Fri, 19 Dec 2014 19:07:22 +0000 |
branch: master
commit a16a665328a25905909d29eefc419591ff47d376
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Initial commit
---
darkroom.el | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 99 insertions(+), 0 deletions(-)
diff --git a/darkroom.el b/darkroom.el
new file mode 100644
index 0000000..e1c59c0
--- /dev/null
+++ b/darkroom.el
@@ -0,0 +1,99 @@
+(defvar darkroom-margins 0.15
+ "Margins to use in darkroom-mode.
+
+It's value can be:
+
+- a floating point value betweeen 0 and 1, specifies percentage of
+ window width in columns to use as a margin.
+
+- a cons cell (LEFT RIGHT) specifying the left and right margins
+ in columns.
+
+- a function that returns a cons cell interpreted like the
+ previous option.
+
+Value is effective when `darkroom-minor-mode' is toggled, when
+changing window or by calling `darkroom-set-margins'")
+
+(defvar darkroom-turns-on-visual-line-mode t
+ "If non-nil pair `visual-line-mode' with
+ `darkroom-minor-mode'")
+(defvar darkroom-fringes-outside-margins t
+ "If non-nil use fringes outside margins for `darkroom-minor-mode'")
+
+(defun darkroom-margins ()
+ (cond ((functionp darkroom-margins)
+ (funcall darkroom-margins))
+ ((consp darkroom-margins)
+ darkroom-margins)
+ ((and (floatp darkroom-margins)
+ (< darkroom-margins 1))
+ (let ((delta (darkroom-float-to-columns darkroom-margins)))
+ (cons delta delta)))))
+
+(defun darkroom-float-to-columns (f)
+ (ceiling (* (let ((edges (window-edges)))
+ (- (nth 2 edges) (nth 0 edges)))
+ f)))
+
+(defun darkroom-set-margins (&optional margins)
+ "Adjust margins to `darkroom-margins' or optional MARGINS."
+ (let ((margins
+ (or margins
+ (darkroom-margins))))
+ (when margins
+ (set-window-margins (selected-window) (car margins) (cdr margins)))))
+
+(defun darkroom-increase-margins ()
+ (interactive)
+ (when (floatp darkroom-margins)
+ (setq darkroom-margins (+ 0.05 darkroom-margins))
+ (darkroom-set-margins)))
+
+(defun darkroom-decrease-margins ()
+ (interactive)
+ (when (floatp darkroom-margins)
+ (setq darkroom-margins (- darkroom-margins 0.05))
+ (darkroom-set-margins)))
+
+(defun darkroom-confirm-fill-paragraph ()
+ (interactive)
+ (when (yes-or-no-p "Really fill paragraph?")
+ (call-interactively 'fill-paragraph)))
+
+(defvar darkroom-minor-mode-map (let ((map (make-sparse-keymap)))
+ (define-key map (kbd "C-M-+")
'darkroom-increase-margins)
+ (define-key map (kbd "C-M--")
'darkroom-decrease-margins)
+ (define-key map (kbd "M-q")
'darkroom-confirm-fill-paragraph)
+ map))
+
+(defvar darkroom-saved-mode-line-format nil)
+(defvar darkroom-saved-visual-mode nil)
+(define-minor-mode darkroom-minor-mode
+ "A minor mode that emulates the darkroom editor."
+ nil
+ " dark"
+ nil
+ (cond (darkroom-minor-mode
+ (setq darkroom-saved-mode-line-format mode-line-format
+ mode-line-format nil)
+ (setq fringes-outside-margins darkroom-fringes-outside-margins)
+ (add-hook 'window-configuration-change-hook 'darkroom-set-margins nil
t)
+ (darkroom-set-margins)
+ (setq header-line-format t)
+ ;; a hack shoulnd't be needed but apparently is
+ (set-window-buffer (selected-window) (current-buffer))
+ (when darkroom-turns-on-visual-line-mode
+ (visual-line-mode 1)))
+ (t
+ (setq header-line-format nil)
+ (setq mode-line-format darkroom-saved-mode-line-format)
+ (when darkroom-turns-on-visual-line-mode
+ (visual-line-mode -1))
+ (remove-hook 'window-configuration-change-hook 'darkroom-set-margins
t)
+ (set-window-margins (selected-window) 0 0))))
+
+
+
+
+(provide 'darkroom)
- [elpa] master 08e7be7 02/26: fix: DARKROOM-CONFIRM-FILL-PARAGRAPH -> DARKROOM-FILL-PARAGRAPH-MAYBE, (continued)
- [elpa] master 08e7be7 02/26: fix: DARKROOM-CONFIRM-FILL-PARAGRAPH -> DARKROOM-FILL-PARAGRAPH-MAYBE, João Távora, 2014/12/19
- [elpa] master 8d2ec73 03/26: fix: save HEADER-LINE-FORMAT as well, João Távora, 2014/12/19
- [elpa] master 21a7919 04/26: first commit, João Távora, 2014/12/19
- [elpa] master 4dc83ad 05/26: darkroom-mode added, João Távora, 2014/12/19
- [elpa] master c6e0c3a 07/26: Leave darkroom-mode when leaving tentative-mode, João Távora, 2014/12/19
- [elpa] master 744d72a 08/26: Add .gitignore, João Távora, 2014/12/19
- [elpa] master 9cd8dfd 06/26: Now works with multiple windows for same darkroom buffer, João Távora, 2014/12/19
- [elpa] master 786b5a3 10/26: Integrate another comment from Rasmus, João Távora, 2014/12/19
- [elpa] master 6cbfebe 09/26: Integrate some comments from Rasmus, João Távora, 2014/12/19
- [elpa] master b36123e 11/26: Tidy up margin calculation, João Távora, 2014/12/19
- [elpa] master a16a665 01/26: Initial commit,
João Távora <=
- [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, 2014/12/19