all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: 24612@debbugs.gnu.org
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)	[thread overview]
Message-ID: <alpine.DEB.2.20.1610042031220.2277@calancha-pc> (raw)


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 <tino.calancha@gmail.com>
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	other threads:[~2016-10-04 11:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-04 11:32 Tino Calancha [this message]
2019-06-25  0:00 ` bug#24612: 26.0.50; calc: insertion/deletion of chars not at point in calc minibuffer Lars Ingebrigtsen
2020-08-11 13:42   ` Lars Ingebrigtsen

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

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

  git send-email \
    --in-reply-to=alpine.DEB.2.20.1610042031220.2277@calancha-pc \
    --to=tino.calancha@gmail.com \
    --cc=24612@debbugs.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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.