unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: PJ Weisberg <pj@irregularexpressions.net>
To: help-gnu-emacs <Help-gnu-emacs@gnu.org>
Cc: Emacs-Devel devel <emacs-devel@gnu.org>
Subject: Re: Free cursor positioning.
Date: Thu, 11 Aug 2011 15:26:52 -0700	[thread overview]
Message-ID: <CAJsNXT=Fiy86s3zUFuUKA42pU748xJxSGp5MezLET5PvH-kzsg@mail.gmail.com> (raw)
In-Reply-To: <j1qeeb$9jj$1@dough.gmane.org>

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	other threads:[~2011-08-11 22:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <j1gaad$1q5$1@dough.gmane.org>
     [not found] ` <BABCE7F96EAF43E6BA4AE96D62251F80@us.oracle.com>
     [not found]   ` <201108052115.19994.vvmarko@gmail.com>
     [not found]     ` <CFA328FB5F5F4693AF857946CC4DEC83@us.oracle.com>
     [not found]       ` <CAJsNXTkYSBkOVxH5t=C+PSY+b5pMTsZ-XcANnZSSw2346CZgyQ@mail.gmail.com>
     [not found]         ` <j1qeeb$9jj$1@dough.gmane.org>
2011-08-11 22:26           ` PJ Weisberg [this message]
2011-08-12 14:27             ` Free cursor positioning Stefan Monnier
2011-08-12 17:41               ` PJ Weisberg
2011-08-21 23:16               ` PJ Weisberg

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to='CAJsNXT=Fiy86s3zUFuUKA42pU748xJxSGp5MezLET5PvH-kzsg@mail.gmail.com' \
    --to=pj@irregularexpressions.net \
    --cc=Help-gnu-emacs@gnu.org \
    --cc=emacs-devel@gnu.org \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).