unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: Free cursor positioning.
       [not found]         ` <j1qeeb$9jj$1@dough.gmane.org>
@ 2011-08-11 22:26           ` PJ Weisberg
  2011-08-12 14:27             ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: PJ Weisberg @ 2011-08-11 22:26 UTC (permalink / raw
  To: help-gnu-emacs; +Cc: Emacs-Devel devel

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



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: Free cursor positioning.
  2011-08-11 22:26           ` Free cursor positioning PJ Weisberg
@ 2011-08-12 14:27             ` Stefan Monnier
  2011-08-12 17:41               ` PJ Weisberg
  2011-08-21 23:16               ` PJ Weisberg
  0 siblings, 2 replies; 4+ messages in thread
From: Stefan Monnier @ 2011-08-12 14:27 UTC (permalink / raw
  To: PJ Weisberg; +Cc: Emacs-Devel devel

> 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.)

The code looks fine to me.

If you package it as a separate file, we could install it in the GNU
ELPA (we could also install it as a patch to picture.el, but since
Emacs-24.1 is in feature freeze, this would have to wait for
Emacs-24.2).


        Stefan


PS: You'd also have to sign some copyright paperwork, of course.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Free cursor positioning.
  2011-08-12 14:27             ` Stefan Monnier
@ 2011-08-12 17:41               ` PJ Weisberg
  2011-08-21 23:16               ` PJ Weisberg
  1 sibling, 0 replies; 4+ messages in thread
From: PJ Weisberg @ 2011-08-12 17:41 UTC (permalink / raw
  To: Stefan Monnier; +Cc: PJ Weisberg, Emacs-Devel devel

[-- Attachment #1: Type: text/plain, Size: 455 bytes --]

On Friday, August 12, 2011, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> PS: You'd also have to sign some copyright paperwork, of course.

It's up to you whether it should be in the core or not.  Just remember that
those missing ^s need to be added in picture.el for shift-selection to
continue to work.

Either way it'll have to wait for copyright assignment.  How do I start that
process?  etc/CONTRIBUTE just says to email emacs-devel.

-- 

-PJ

[-- Attachment #2: Type: text/html, Size: 556 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Free cursor positioning.
  2011-08-12 14:27             ` Stefan Monnier
  2011-08-12 17:41               ` PJ Weisberg
@ 2011-08-21 23:16               ` PJ Weisberg
  1 sibling, 0 replies; 4+ messages in thread
From: PJ Weisberg @ 2011-08-21 23:16 UTC (permalink / raw
  To: Stefan Monnier; +Cc: Emacs-Devel devel

[-- Attachment #1: Type: text/plain, Size: 1856 bytes --]

On Fri, Aug 12, 2011 at 7:27 AM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
>> 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.)
>
> The code looks fine to me.
>
> If you package it as a separate file, we could install it in the GNU
> ELPA (we could also install it as a patch to picture.el, but since
> Emacs-24.1 is in feature freeze, this would have to wait for
> Emacs-24.2).
>
>
>        Stefan
>
>
> PS: You'd also have to sign some copyright paperwork, of course.

I emailed assign@gnu.org a week ago.  Are they supposed to reply with
an acknowledgement that they're sending the papers, or do I just watch
my postal mail and wait?

I attached the file that would go in Gnu ELPA.  This seems like
something someone would want to enable globally, so I included a
`define-global-minor-mode'.  Problems come up, though, when the
picture-move-* commands try to insert spaces in read only text, and
they don't work well with fields like those in Customize buffers.

One thing I could do is make quarter-plane-move-* commands that call
either the picture commands or the normal movement commands depending
on whether the buffer is read-only, or something similar to handle
when only parts of the buffer are read-only.

picture-move-down still wouldn't move past a field in the Customize
buffer, though.  It looks like the problem is that if point is on the
same line as a field, but in the text before the start of the field,
`end-of-line' takes point to the beginning of the field instead of the
end of the line.  `picture-newline' then incorrectly assumes that
`forward-char' will take it to the next line.

Any ideas on how I could get it to work properly as a global minor mode?

[-- Attachment #2: quarter-plane.el --]
[-- Type: text/x-emacs-lisp, Size: 3404 bytes --]

;;; quarter-plane.el --- editing using quarter-plane screen model

;; Copyright (C) 2011 Peter J. Weisberg

;; Author: Peter J. Weisberg
;; Version: 0.1
;; Keywords: convenience wp

;; This program 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, either version 3 of the License, or
;; (at your option) any later version.

;; This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; This code provides a minor mode to enable the some of picture-mode
;; commands documented in the Emacs manual in order to treat the
;; screen as a semi-infinite quarter-plane, without changing the
;; buffer's major mode.

;; Known issues:

;; Quarter-Plane mode doesn't work in read-only buffers, where it
;; can't insert spaces.

;; The user doesn't really care about the "modifications" of adding
;; whitespace that's going to be trimmed when he exits quarter-plane
;; mode or saves, but it's still part of the undo history.

;; Both of these are due to the disconnect between what the user
;; really wants--movement of the cursor within the window, regardless
;; of where the text is--and what the mode can actually do--add dummy
;; text to give the cursor a place to move to.

;;; Code:

(require 'picture)

(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.

Because it works by inserting spaces, Quarter-Plane mode won't work in
read-only buffers

\\{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)))

;;;###autoload
(defun turn-on-quarter-plane-mode ()
  "Turn on `quarter-plane-mode'."
  (quarter-plane-mode 1))

;;;###autoload
(define-global-minor-mode global-quarter-plane-mode quarter-plane-mode
  turn-on-quarter-plane-mode
  :group 'picture)

(defun quarter-plane-delete-whitespace ()
  "Call `delete-trailing-whitespace' if the buffer is not read-only."
  (if (not buffer-read-only)
      (delete-trailing-whitespace)))

(add-hook 'quarter-plane-mode-off-hook 'quarter-plane-delete-whitespace)

(provide 'quarter-plane)

;;; quarter-plane.el ends here

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-08-21 23:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [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           ` Free cursor positioning PJ Weisberg
2011-08-12 14:27             ` Stefan Monnier
2011-08-12 17:41               ` PJ Weisberg
2011-08-21 23:16               ` PJ Weisberg

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).