help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Free cursor positioning.


From: PJ Weisberg
Subject: Re: Free cursor positioning.
Date: Thu, 11 Aug 2011 15:26:52 -0700

On Mon, Aug 8, 2011 at 9:53 PM, Kevin Rodgers <kevin.d.rodgers@gmail.com> wrote:
> On 8/5/11 5:03 PM, PJ Weisberg wrote:
>> The thing is, when you're in picture mode, you're *not* in C mode,
>> perl mode, or whatever mode you really want to be in.  He just wants a
>> few features of picture mode to be on all the time.  Something like:
>>
>> (require 'picture)
>> (global-set-key (kbd "<right>") 'picture-forward-column)
>> (global-set-key (kbd "<up>") 'picture-move-up)
>> (global-set-key (kbd "<down>") 'picture-move-down)
>> (add-hook 'before-save-hook 'delete-trailing-whitespace)
>
> Wrap it in define-global-minor-mode, and/or change the global bindings and
> hook
> to locals and wrap that in define-minor-mode.

The problem with that is that the keybindings don't go away when you
turn off the minor mode.  And local-set-key actually affects every
buffer that uses the same keymap as the current buffer (probably every
buffer with the same major mode).

IMO, this is something that would make sense as a built-in minor mode,
something like this.  (Excuse the Git patch format; I've never gotten
around to learning Bazaar.)

======================================================================

>From d54542c54d1319844df3a4d9cdb1375ca6edffdc Mon Sep 17 00:00:00 2001
From: "Peter J. Weisberg" <pj@irregularexpressions.net>
Date: Thu, 11 Aug 2011 13:53:25 -0700
Subject: [PATCH] lisp/textmodes/picture.el (quarter-plane-mode): New minor
 mode to use quarter-plane movement functions outside of
 picture mode

---
 lisp/textmodes/picture.el |   39 +++++++++++++++++++++++++++++++++++----
 1 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/lisp/textmodes/picture.el b/lisp/textmodes/picture.el
index 8148378..337ee91 100644
--- a/lisp/textmodes/picture.el
+++ b/lisp/textmodes/picture.el
@@ -101,7 +101,7 @@ If scan reaches end of buffer, stop there without error."
 (defun picture-forward-column (arg &optional interactive)
   "Move cursor right, making whitespace if necessary.
 With argument, move that many columns."
-  (interactive "p\nd")
+  (interactive "^p\nd")
   (let (deactivate-mark)
     (picture-update-desired-column interactive)
     (setq picture-desired-column (max 0 (+ picture-desired-column arg)))
@@ -115,14 +115,14 @@ With argument, move that many columns."
 (defun picture-backward-column (arg &optional interactive)
   "Move cursor left, making whitespace if necessary.
 With argument, move that many columns."
-  (interactive "p\nd")
+  (interactive "^p\nd")
   (picture-update-desired-column interactive)
   (picture-forward-column (- arg)))

 (defun picture-move-down (arg)
   "Move vertically down, making whitespace if necessary.
 With argument, move that many lines."
-  (interactive "p")
+  (interactive "^p")
   (let (deactivate-mark)
     (picture-update-desired-column nil)
     (picture-newline arg)
@@ -139,7 +139,7 @@ With argument, move that many lines."
 (defun picture-move-up (arg)
   "Move vertically up, making whitespace if necessary.
 With argument, move that many lines."
-  (interactive "p")
+  (interactive "^p")
   (picture-update-desired-column nil)
   (picture-move-down (- arg)))

@@ -786,6 +786,37 @@ Runs `picture-mode-exit-hook' at the end."
     (force-mode-line-update)
     (run-hooks 'picture-mode-exit-hook)))

+(defvar quarter-plane-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map [remap right-char] 'picture-forward-column)
+    (define-key map [remap forward-char] 'picture-forward-column)
+    (define-key map [remap previous-line] 'picture-move-up)
+    (define-key map [remap next-line] 'picture-move-down)
+    (define-key map [remap mouse-set-point] 'picture-mouse-set-point)
+    map))
+
+;;;###autoload
+(define-minor-mode quarter-plane-mode
+  "Toggle Quarter-Plane mode on or off.
+Interactively, with no prefix argument, toggle the mode.
+With universal prefix ARG turn mode on.
+With zero or negative ARG turn mode off.
+
+Use point movement commands that act as if the text extended
+infinitely down and to the right, inserting spaces as necessary.
+Excess whitespace is trimmed when saving or exiting Quarter-Plane mode.
+\\{quarter-plane-mode-map}"
+  :lighter " Plane"
+  :group 'picture
+  :keymap quarter-plane-mode-map
+  (if quarter-plane-mode
+      (add-hook 'before-save-hook 'quarter-plane-delete-whitespace nil t)
+    (remove-hook 'before-save-hook 'quarter-plane-delete-whitespace t)))
+
+(defalias 'quarter-plane-delete-whitespace 'delete-trailing-whitespace)
+
+(add-hook 'quarter-plane-mode-off-hook 'delete-trailing-whitespace)
+
 (provide 'picture)

 ;;; picture.el ends here
--
1.7.6.553.g917d7

-PJ



reply via email to

[Prev in Thread] Current Thread [Next in Thread]