;;; blockwrite-mode.el --- emacs text mode for brainstorming (no revising allowed!) ;; This code is copyright (C) 2006 Sean M. Burke ;; Time-stamp: "2006-07-02 20:18:57 ADT" ;; Author: Sean M. Burke ;; Maintainer: Sean M. Burke ;; Version: 1.0.1 ;; Keywords: wp ;;; Commentary: ;; ;; blockwrite-mode.el is a text mode for brainstorming or otherwise making ;; yourself *write* instead of revise. ;; ;; Start a new file, turn on blockwrite-mode, and start writing! ;; ;; This is based on an idea by Khoi Vinh http://blockwriter.com/ , who will ;; probably have a proper fully-feature(d|less) implementation at that web ;; site soonish. Until this, consider this mode a sort of emulation, in ;; the same way that vi.el is an emulation of vi. ;; ;; Note: no overstriking/strikeout support yet, as that would seem to involve ;; corners of elisp that I don't understand in the least. If you want to ;; fake-delete a word, just type XXX after it. ;; ;; You install and activate this mode as you would for any other emacs ;; mode. Ask your system admins for help if that's unclear. And ;; bring them chocolates. Everyone likes chocolates. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;~~Boilerplate~~ ;; This file is not part of GNU Emacs. ;; ;; This is free software; you can redistribute it and/or modify it under the ;; terms of the GNU General Public License as published by the Free Software ;; Foundation, version 2. ;; ;; This is distributed in the hope that it will be useful, but without any ;; warranty without even the implied warranty of merchantability or fitness for ;; a particular purpose. See the GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License along with ;; GNU Emacs; see the file COPYING. If not, write to the Free Software ;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ;;;~~End Boilerplate~~ ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Change log: ;; ;; 2006-07-02 version 1.0.1 ;; A beta for public consideration. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Code: (defvar blockwrite-greeting "Blockwrite is on. Now maximize this window and get to work!" "*The message we emit on entering blockwrite mode.") (defvar blockwrite-save-often t "*Whether to automatically save the blockwrite files often.") (defvar blockwrite-functions-to-block '( kill-rectangle kill-region kill-comment kill-line kill-paragraph backward-kill-paragraph kill-sentence backward-kill-sentence kill-sexp backward-kill-sexp kill-word backward-kill-word delete-char backward-delete-char-untabify delete-backward-char delete-extract-rectangle delete-field delete-matching-lines delete-non-matching-lines delete-rectangle delete-region yank yank-pop yank-rectangle ; Untypwriterish: undo negative-argument digit-argument universal-argument ;; But might as well leave alone the functions that affect just whitespace: ; delete-to-left-margin ; delete-trailing-whitespace ; delete-horizontal-space ; delete-indentation ; delete-minibuffer-contents ; delete-blank-lines ) "*The list of editing commands that Blockwrite blocks the keys for" ) ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; (defun blockwrite-greet () "Tell the user we're in blockmode now" (when blockwrite-greeting (message blockwrite-greeting))) (defun blockwrite-hide-tabs () "Turn off the buffer tabs ('gutter')" (blockwrite-xnil 'default-gutter-visible-p)) (defun blockwrite-hide-toolbar () "Turn off the toolbar" (blockwrite-xnil 'default-toolbar-visible-p) (blockwrite-e0 'tool-bar-mode)) (defun blockwrite-hide-menubar () "Turn off the menubar" (blockwrite-xnil 'menubar-visible-p) (blockwrite-e0 'menu-bar-mode)) (add-hook 'blockwrite-mode-hook 'blockwrite-greet) (add-hook 'blockwrite-mode-hook 'delete-other-windows) (add-hook 'blockwrite-mode-hook 'blockwrite-hide-tabs) (add-hook 'blockwrite-mode-hook 'blockwrite-hide-toolbar) (add-hook 'blockwrite-mode-hook 'blockwrite-hide-menubar) ;;;###autoload (define-derived-mode blockwrite-mode text-mode ;our base "Blockwrite" "Major mode for brainstorming text. This mode is like normal text-mode except that it blocks you from deleting text, thus forcing you to always go forward instead of revising." (blockwrite-block-keys) (local-set-key "\C-m" 'blockwrite-newline) ) (defun blockwrite-newline () (interactive) (newline) (setq buffer-undo-list nil) (when (and blockwrite-save-often (not (null buffer-file-name))) (save-buffer))) (byte-compile 'blockwrite-newline) ; for superspeed! ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; It's just increasingly-ugly internals from here on out: (defun blockwrite-noop () "A no-operation" (interactive) (progn)) (byte-compile 'blockwrite-noop) ; if ever we want blocked keys to just silently do nothing (defun blockwrite-block-keys () "puts deletion-blockers in the new keymap" (dolist (fn blockwrite-functions-to-block) (dolist (key (where-is-internal fn)) (define-key blockwrite-mode-map key (blockwrite-rebuking key fn))))) (defun blockwrite-rebuking (key fn) (let ( (rebuke (format "Blockwrite stops %s calling %s" (key-description key) (symbol-name fn) )) (desc (format "Blocking %s !" (key-description key))) ) ; And now, for lack of easy closures in elisp, we get do it the weird way: (byte-compile (list 'lambda '() rebuke '(interactive) '(beep) (list 'message desc))))) (defun blockwrite-xnil (specsym) ; If we're under xemacs, set the given symbol's specifier to nil. (when (and (featurep 'xemacs) (boundp specsym) (specifierp (symbol-value specsym))) (set-specifier (symbol-value specsym) nil)) nil) (defun blockwrite-e0 (fsym) ; If we're not under xemacs, call the given function with a param '0'. (when (and (not (featurep 'xemacs)) (fboundp fsym)) (apply fsym '(0))) nil) ;; ; ; I found this very helpful in writing this mode: ; http://www.emacswiki.org/cgi-bin/wiki/DerivedMode ;; ; (provide 'blockwrite-mode) ;;; blockwrite-mode.el ends here