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

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

bug#24612: 26.0.50; calc: insertion/deletion of chars not at point in ca


From: Tino Calancha
Subject: bug#24612: 26.0.50; calc: insertion/deletion of chars not at point in calc minibuffer
Date: Tue, 4 Oct 2016 20:32:18 +0900 (JST)
User-agent: Alpine 2.20 (DEB 67 2015-01-07)


It is very counter-intuitive how to modify things in the calc minibuffer.
Insertions and deletions are respect to the digit in the right hand side.
You can set the point before any digit, but <backspace> will always delete
the last one.

emacs -Q

M-x calc RET
9123
I) C-a C-d ; Delete 3 instead of 9, number:912
II) C-b C-b; Point is right after 9.
III) <backspace> ; Delete 2 instead of 9, number: 91
IV) C-a 8 ; Number: 918 instead of 891.

I find easier if the behaviour is as follows:
M-x calc RET
9123
I) C-a C-d ; number: 123
II) C-e C-b ; Point is right after 2.
III) <backspace> ; number: 13
IV) C-a 8 ; number: 813

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
From fc4ac0c2a32ebb771583514dc6519539eaa9ac9b Mon Sep 17 00:00:00 2001
From: Tino Calancha <address@hidden>
Date: Tue, 4 Oct 2016 20:23:29 +0900
Subject: [PATCH] calc: insert/delete chars in calc minibuffer at point

* lisp/calc/calc.el (calcDigit-delchar): New command to delete chars
forward in the calc minibuffer.
(calc-digit-map): Bind calcDigit-delchar to '\C-d'.
(calcDigit-key): Do not go to (point-max) in calc minibuffer
before insert a digit (Bug#24612).
---
 lisp/calc/calc.el | 50 ++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 36 insertions(+), 14 deletions(-)

diff --git a/lisp/calc/calc.el b/lisp/calc/calc.el
index 7ae8fdf..c230ed9 100644
--- a/lisp/calc/calc.el
+++ b/lisp/calc/calc.el
@@ -1120,8 +1120,26 @@ calc-digit-map
          (append (where-is-internal 'delete-backward-char global-map)
                  (where-is-internal 'backward-delete-char global-map)
                  (where-is-internal 'backward-delete-char-untabify global-map)
-                 '("\C-d"))
-       '("\177" "\C-d")))
+                 '("\177"))
+       '("\177")))
+
+(mapc (lambda (x)
+        (ignore-errors
+          (define-key calc-digit-map x 'calcDigit-delchar)
+          (define-key calc-mode-map x 'calc-pop)
+          (define-key calc-mode-map
+            (if (and (vectorp x) (featurep 'xemacs))
+                (if (= (length x) 1)
+                    (vector (if (consp (aref x 0))
+                                (cons 'meta (aref x 0))
+                              (list 'meta (aref x 0))))
+                  "\e\C-d")
+              (vconcat "\e" x))
+            'calc-pop-above)))
+      (if calc-scan-for-dels
+          (append (where-is-internal 'delete-forward-char global-map)
+                  '("\C-d"))
+        '("\C-d")))

 (defvar calc-dispatch-map
   (let ((map (make-keymap)))
@@ -2383,7 +2401,6 @@ calc-minibuffer-contains

 (defun calcDigit-key ()
   (interactive)
-  (goto-char (point-max))
   (if (or (and (memq last-command-event '(?+ ?-))
               (> (buffer-size) 0)
               (/= (preceding-char) ?e))
@@ -2426,8 +2443,7 @@ calcDigit-key
            (delete-char 1))
        (if (looking-at "-")
            (delete-char 1)
-         (insert "-")))
-      (goto-char (point-max)))
+         (insert "-"))))
      ((eq last-command-event ?p)
       (if (or (calc-minibuffer-contains ".*\\+/-.*")
              (calc-minibuffer-contains ".*mod.*")
@@ -2480,17 +2496,9 @@ calcDigit-key
   (setq calc-prev-prev-char calc-prev-char
        calc-prev-char last-command-event))

-
 (defun calcDigit-backspace ()
   (interactive)
-  (goto-char (point-max))
-  (cond ((calc-minibuffer-contains ".* \\+/- \\'")
-        (backward-delete-char 5))
-       ((calc-minibuffer-contains ".* mod \\'")
-        (backward-delete-char 5))
-       ((calc-minibuffer-contains ".* \\'")
-        (backward-delete-char 2))
-       ((eq last-command 'calcDigit-start)
+  (cond ((eq last-command 'calcDigit-start)
         (erase-buffer))
        (t (backward-delete-char 1)))
   (if (= (calc-minibuffer-size) 0)
@@ -2499,6 +2507,20 @@ calcDigit-backspace
        (calcDigit-nondigit))))


+(defun calcDigit-delchar ()
+  (interactive)
+  (cond ((looking-at-p " \\+/- \\'")
+         (delete-char 5))
+       ((looking-at-p " mod \\'")
+        (delete-char 5))
+       ((looking-at-p " \\'")
+        (delete-char 2))
+       ((eq last-command 'calcDigit-start)
+        (erase-buffer))
+       (t (unless (eobp) (delete-char 1))))
+  (when (= (calc-minibuffer-size) 0)
+    (setq last-command-event 13)
+    (calcDigit-nondigit)))


 (defconst math-bignum-digit-length
--
2.9.3

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

In GNU Emacs 26.0.50.4 (x86_64-pc-linux-gnu, GTK+ Version 3.22.0)
 of 2016-10-04 built on calancha-pc
Repository revision: e2913dc880b9843bf69cf885270551bafeb46120





reply via email to

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