commit 05506ad064908b4196cfda0c0bdacdeb1a8ac993
parent b349809aa5aec46bfe08a7df7ee99d4a9f61e778
Author: Ryan Jeffrey <pwishie@gmail.com>
Date: Fri, 24 May 2019 23:07:09 -0700
Undo and redo
Diffstat:
2 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/README.org b/README.org
@@ -1,5 +1,15 @@
* Joestar
Joestar is a minor mode for emacs that seeks to emulate [[https://github.com/jhallen/joe-editor][Joe's Own Editor]], a wordstar-like terminal text editor.
+* Joestar and undo-tree
+Joestar depends on undo-tree, which uses C-x for several of its keybindings, which conflicts with Joestar's usage of C-x.
+In order to fix this, Joestar remaps the three following functions:
+#+BEGIN_SRC emacs-lisp
+
+(define-key map (kbd "s-x u") 'undo-tree-visualize)
+(define-key map (kbd "s-x r u") 'undo-tree-save-state-to-register)
+(define-key map (kbd "s-x r U") 'undo-tree-restore-state-from-register)
+
+#+END_SRC
* Tutorial
** A note on Control key sequences
Because of the way that Joe works *C-k C-e* is the same as *C-k e*, whereas Emacs considers those to be different key sequences. In joestar mode, just like in joe, these are the same sequence.
diff --git a/joestar.el b/joestar.el
@@ -4,8 +4,8 @@
;;; Author: Ryan Jeffrey <pwishie@gmail.com>
;;; Keywords: joe wordstar
-;;; Version 0.1
-;;; Package-Requires: ((emacs "24.2"))
+;;; Version 0.2
+;;; Package-Requires: ((emacs "24.2") (undo-tree 0.8.5))
;;; Commentary:
@@ -100,14 +100,15 @@
(interactive)
(call-interactively 'backward-word)
(call-interactively 'kill-word))) ;; TODO, Test
-
(define-key joe-map (kbd "C-^") '(lambda ()
- "Undo-tree redo."
- (call-interactively 'redo)))
+ "Calls undo-tree redo."
+ (interactive)
+ (call-interactively 'undo-tree-redo)))
(define-key joe-map (kbd "C-_") '(lambda ()
- "Undo-tree undo."
- (call-interactively 'undo)))
+ "Calls undo-tree undo."
+ (interactive)
+ (call-interactively 'undo-tree-undo)))
(define-key joe-map (kbd "C-k C-x") 'save-buffers-kill-emacs)
(define-key joe-map (kbd "C-k C-x") (kbd "C-k C-x"))
@@ -244,7 +245,27 @@
;; keep cursor position while scrolling
(setq scroll-preserve-screen-position 'always) ; TODO fix behavior so that it always scrolls perfectly
(setq scroll-error-top-bottom t)
- )
+ (defvar undo-tree-map
+ (let ((map (make-sparse-keymap)))
+ ;; remap `undo' and `undo-only' to `undo-tree-undo'
+ (define-key map [remap undo] 'undo-tree-undo)
+ (define-key map [remap undo-only] 'undo-tree-undo)
+ ;; bind standard undo bindings (since these match redo counterparts)
+ (define-key map (kbd "C-/") 'undo-tree-undo)
+ (define-key map "\C-_" 'undo-tree-undo)
+ ;; redo doesn't exist normally, so define our own keybindings
+ (define-key map (kbd "C-?") 'undo-tree-redo)
+ (define-key map (kbd "M-_") 'undo-tree-redo)
+ ;; just in case something has defined `redo'...
+ (define-key map [remap redo] 'undo-tree-redo)
+ ;; we use "C-x u" for the undo-tree visualizer
+ (define-key map (kbd "s-x u") 'undo-tree-visualize)
+ ;; bind register commands
+ (define-key map (kbd "s-x r u") 'undo-tree-save-state-to-register)
+ (define-key map (kbd "s-x r U") 'undo-tree-restore-state-from-register)
+ ;; set keymap
+ (setq undo-tree-map map)))
+ (undo-tree-mode t))
(define-globalized-minor-mode global-joestar-mode joestar-mode
(lambda () (joestar-mode 1)))