GNU bug report logs -
#21648
25.0.50; [PATCH] Add ability to specify radix for the yanked number in calc-yank
Previous Next
Reported by: Kaushal Modi <kaushal.modi <at> gmail.com>
Date: Thu, 8 Oct 2015 15:10:01 UTC
Severity: wishlist
Tags: patch
Found in version 25.0.50
Done: Kaushal Modi <kaushal.modi <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your bug report
#21648: 25.0.50; [PATCH] Add ability to specify radix for the yanked number in calc-yank
which was filed against the emacs package, has been closed.
The explanation is attached below, along with your original report.
If you require more details, please reply to 21648 <at> debbugs.gnu.org.
--
21648: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=21648
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
[Message part 3 (text/plain, inline)]
Closing this debbugs as the patch is now commited to the trunk:
http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=ec0d4d24fd11b5040de9f7657b486c3b1e743071
Many thanks to Jay for a very active feedback session, helping make the
final patch much more robust than the initial version.
[Message part 4 (text/html, inline)]
[Message part 5 (message/rfc822, inline)]
[Message part 6 (text/plain, inline)]
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 <at> 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
[Message part 7 (text/html, inline)]
This bug report was last modified 9 years and 225 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.