all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#21648: 25.0.50; [PATCH] Add ability to specify radix for the yanked number in calc-yank
@ 2015-10-08 15:07 Kaushal Modi
  2015-10-08 16:08 ` Jay Belanger
  0 siblings, 1 reply; 11+ messages in thread
From: Kaushal Modi @ 2015-10-08 15:07 UTC (permalink / raw)
  To: 21648, jay.p.belanger

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

Hi,

I read this question of emacs.stackexchange (
http://emacs.stackexchange.com/q/13451/115 ) where the user needed to
specify the radix of the number he was pasting in calc.

If the calc default radix is decimal and if a user pastes 1000, it will be
pasted as decimal 1000. But what if the user meant to paste binary 1000
(decimal 8)?

My patch below enables doing that using numeric prefixes.

Please advise if merging this patch to calc-yank is a good idea or if needs
improvement/bug fixes before the merging. I have used this modified
calc-yank function for few weeks and did not mess up anything else in my
calc usage.




======================================================

From fa9c8f6c2cce1c9e69bd6f6c25f036a72e0b799b Mon Sep 17 00:00:00 2001
From: Kaushal Modi <kaushal.modi@gmail.com>
Date: Thu, 8 Oct 2015 10:56:36 -0400
Subject: [PATCH] Prepend radix to yanked numbers using num prefix

If 1000 is the last element saved to the kill-ring.

Then,

C-2 C-y will paste 8 (2#1000),
C-8 C-y will paste 512 (8#1000),
C-0 C-y will paste 1000 (10#1000),
C-6 C-y will paste 4096 (16#1000)
.. and C-y will paste 1000 (1000).
---
 lisp/calc/calc-yank.el | 45 ++++++++++++++++++++++++++++++---------------
 1 file changed, 30 insertions(+), 15 deletions(-)

diff --git a/lisp/calc/calc-yank.el b/lisp/calc/calc-yank.el
index 5694a4e..811b308 100644
--- a/lisp/calc/calc-yank.el
+++ b/lisp/calc/calc-yank.el
@@ -111,25 +111,40 @@ calc-copy-region-as-kill
 ;; otherwise it just parses the yanked string.
 ;; Modified to use Emacs 19 extended concept of kill-ring. -- daveg
12/15/96
 ;;;###autoload
-(defun calc-yank ()
-  (interactive)
+(defun calc-yank (radix)
+  "Yank a value into the Calculator buffer.
+
+If RADIX is nil, do not prepend any radix notation.
+
+If RADIX is 2, prepend \"2#\" (The yanked number will be perceived as
binary.)
+If RADIX is 8, prepend \"8#\" (The yanked number will be perceived as
octal.)
+If RADIX is 0, prepend \"10#\" (The yanked number will be perceived as
decimal.)
+If RADIX is 16, prepend \"16#\" (The yanked number will be perceived as
hexadecimal.) "
+  (interactive "P")
   (calc-wrapper
    (calc-pop-push-record-list
     0 "yank"
-    (let ((thing (if (fboundp 'current-kill)
-     (current-kill 0 t)
-   (car kill-ring-yank-pointer))))
+    (let* ((radix-notation (cl-case radix
+                             (2 "2#")
+                             (8 "8#")
+                             (0 "10#")
+                             (6 "16#")
+                             (t "")))
+           (thing (concat radix-notation
+                          (if (fboundp 'current-kill)
+                              (current-kill 0 t)
+                            (car kill-ring-yank-pointer)))))
       (if (eq (car-safe calc-last-kill) thing)
-  (cdr calc-last-kill)
- (if (stringp thing)
-    (let ((val (math-read-exprs (calc-clean-newlines thing))))
-      (if (eq (car-safe val) 'error)
-  (progn
-    (setq val (math-read-exprs thing))
-    (if (eq (car-safe val) 'error)
- (error "Bad format in yanked data")
-      val))
- val))))))))
+          (cdr calc-last-kill)
+        (if (stringp thing)
+            (let ((val (math-read-exprs (calc-clean-newlines thing))))
+              (if (eq (car-safe val) 'error)
+                  (progn
+                    (setq val (math-read-exprs thing))
+                    (if (eq (car-safe val) 'error)
+                        (error "Bad format in yanked data")
+                      val))
+                val))))))))

 ;;; The Calc set- and get-register commands are modified versions of
functions
 ;;; in register.el
-- 
2.6.0.rc0.24.gec371ff

======================================================


PS: My copyright paperwork is on file (#1029578)

--
Kaushal Modi

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

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

end of thread, other threads:[~2015-10-12 13:16 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-08 15:07 bug#21648: 25.0.50; [PATCH] Add ability to specify radix for the yanked number in calc-yank Kaushal Modi
2015-10-08 16:08 ` Jay Belanger
2015-10-08 16:19   ` Kaushal Modi
2015-10-08 16:59     ` Kaushal Modi
2015-10-08 19:26       ` Jay Belanger
2015-10-08 20:35         ` Kaushal Modi
2015-10-09  1:04           ` Jay Belanger
2015-10-09  2:56             ` Kaushal Modi
     [not found]               ` <8737xk7nge.fsf@gmail.com>
     [not found]                 ` <CAFyQvY3YBu1x4wcib++K_mTGfRNLqBfPBaj90rYJriZAuk-9Gg@mail.gmail.com>
     [not found]                   ` <CAFyQvY04LqeGAwyWMGFFDpHDqkb1TbW+vfH9drHruq6+yhVRpw@mail.gmail.com>
     [not found]                     ` <87twq0dkqd.fsf@gmail.com>
     [not found]                       ` <CAFyQvY1-yu9QQhzaQLVv9MLLkBQmOxY=usidbguSJnr9xwKp6g@mail.gmail.com>
     [not found]                         ` <87vbael6ph.fsf@gmail.com>
     [not found]                           ` <CAFyQvY07v3P2bjUQ+PAJbvUQu_nXV=k+umVW-JeKK2r=uWS=_Q@mail.gmail.com>
     [not found]                             ` <87twpyuz1q.fsf@gmail.com>
     [not found]                               ` <CAFyQvY3BbgGimetANnnZ-P13KXvH54_QHqcYF3sAiPWFaz=NFA@mail.gmail.com>
     [not found]                                 ` <87vbaeib5o.fsf@gmail.com>
2015-10-12 13:16                                   ` Kaushal Modi
2015-10-08 16:30   ` Eli Zaretskii
2015-10-08 18:11     ` Jay Belanger

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.