From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kaushal Modi Newsgroups: gmane.emacs.bugs Subject: bug#21648: 25.0.50; [PATCH] Add ability to specify radix for the yanked number in calc-yank Date: Thu, 8 Oct 2015 11:07:38 -0400 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a113cd6d2a1d97b0521993b37 X-Trace: ger.gmane.org 1444343711 30587 80.91.229.3 (8 Oct 2015 22:35:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 8 Oct 2015 22:35:11 +0000 (UTC) To: 21648@debbugs.gnu.org, jay.p.belanger@gmail.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Oct 09 00:35:04 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from eggs.gnu.org ([208.118.235.92]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZkJm4-0002uu-UH for geb-bug-gnu-emacs@m.gmane.org; Fri, 09 Oct 2015 00:34:57 +0200 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZkJlm-0001AE-Dv for geb-bug-gnu-emacs@m.gmane.org; Thu, 08 Oct 2015 18:34:56 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: * X-Spam-Status: No, score=1.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, HTML_FONT_FACE_BAD,HTML_MESSAGE,T_DKIM_INVALID,T_RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:51550) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkJlm-00018l-13 for geb-bug-gnu-emacs@m.gmane.org; Thu, 08 Oct 2015 18:34:38 -0400 Original-Received: from localhost ([::1]:37509 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkJll-0005oz-KH for geb-bug-gnu-emacs@m.gmane.org; Thu, 08 Oct 2015 18:34:37 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55248) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkJlf-0005oY-Ib for bug-gnu-emacs@gnu.org; Thu, 08 Oct 2015 18:34:33 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZkJld-0000vM-UE for bug-gnu-emacs@gnu.org; Thu, 08 Oct 2015 18:34:31 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:43807) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkCpW-0000Vd-VB for bug-gnu-emacs@gnu.org; Thu, 08 Oct 2015 11:10:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1ZkCpW-0000F9-BR for bug-gnu-emacs@gnu.org; Thu, 08 Oct 2015 11:10:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Kaushal Modi Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 08 Oct 2015 15:10:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 21648 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: "bug-gnu-emacs@gnu.org" , jay.p.belanger@gmail.com Original-Received: via spool by submit@debbugs.gnu.org id=B.1444316946854 (code B ref -1); Thu, 08 Oct 2015 15:10:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 8 Oct 2015 15:09:06 +0000 Original-Received: from localhost ([127.0.0.1]:32775 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZkCob-0000Dg-T0 for submit@debbugs.gnu.org; Thu, 08 Oct 2015 11:09:06 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:47559) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZkCoZ-0000DH-8U for submit@debbugs.gnu.org; Thu, 08 Oct 2015 11:09:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZkCo2-0003oe-Mq for submit@debbugs.gnu.org; Thu, 08 Oct 2015 11:09:03 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:43033) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkCo2-0003m4-0A for submit@debbugs.gnu.org; Thu, 08 Oct 2015 11:08:30 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54937) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkCny-0002oZ-DK for bug-gnu-emacs@gnu.org; Thu, 08 Oct 2015 11:08:29 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZkCnr-0003B5-4q for bug-gnu-emacs@gnu.org; Thu, 08 Oct 2015 11:08:25 -0400 Original-Received: from mail-oi0-x22f.google.com ([2607:f8b0:4003:c06::22f]:35562) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZkCnq-00038g-Dn for bug-gnu-emacs@gnu.org; Thu, 08 Oct 2015 11:08:18 -0400 Original-Received: by oigi138 with SMTP id i138so6455007oig.2 for ; Thu, 08 Oct 2015 08:08:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=hp9X4cWwohMWBr9OVkY24ejGDwdEhcaxYcYc4umPI0A=; b=QxkGOXsBpxEnmRQLeTXMMDe0DmYgReUZqraEbdpNZk8FvQe1xqgH1bVIQgoUIZbAb/ 9J5k2FShrVk13aO0DY37WwQ33Y16f7WGw7e/NV2qeynLlRkQTEqLYmEsAEW+/RyV93xf Lf9Nul4fg+ih/xYeiQG2THDgl8DQzm5MTudXQkfJVEyGgmQRpkJ9R7u+JeeaTNjG2+tr h5kdA9qGULMHls0SbdwetJ0JnyKV7QaraiokTs9Wy2rXv4qXRHuZvsgFrpVviWWnKUpe wWZz3+Co59Hfx83bdrzmTvvOwcjNeBaRyTo3XBcqoLbV/NdWnm6oBhSJmFVLoP1c4e/X GYzQ== X-Received: by 10.202.65.136 with SMTP id o130mr4641784oia.134.1444316897726; Thu, 08 Oct 2015 08:08:17 -0700 (PDT) Original-Received: by 10.202.172.205 with HTTP; Thu, 8 Oct 2015 08:07:38 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 Xref: news.gmane.org gmane.emacs.bugs:107466 Archived-At: --001a113cd6d2a1d97b0521993b37 Content-Type: text/plain; charset=UTF-8 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 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 --001a113cd6d2a1d97b0521993b37 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,

I read this question of emacs.stackexchange (= =C2=A0http://emacs.s= tackexchange.com/q/13451/115 ) where the user needed to specify the rad= ix of the number he was pasting in calc.

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

My patch below enable= s doing that using numeric prefixes.

Please advise if merging this patch to calc-yank is a good idea or if need= s 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 us= age.



<= /font>

<= font face=3D"trebuchet ms, sans-serif">=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

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

<= div class=3D"gmail_default" style=3D"">If 1000 is the last element saved to the kill-ring.
Then,

C-2 C-y wi= ll 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 wi= ll paste 4096 (16#1000)
.. and C-y will paste 1000 (1000).=
---
<= font face=3D"trebuchet ms, sans-serif">=C2=A0lisp/calc/calc-yank.el | 45 ++= ++++++++++++++++++++++++++++---------------
=C2=A01 file c= hanged, 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/cal= c-yank.el
+++ b/lisp/calc/calc-yank.el
@@= -111,25 +111,40 @@ calc-copy-region-as-kill
=C2=A0;; othe= rwise it just parses the yanked string.
=C2=A0;; Modified = to use Emacs 19 extended concept of kill-ring. -- daveg 12/15/96
=C2=A0;;;###autoload
-(defun calc-yank ()
- =C2=A0(interactive)
+(defun calc-yank (radix)
+ =C2=A0"Yank a value into the Calculator buffer.
+
+If RADIX is nil, do not prepend any radix = notation.
+
+If RADIX is 2, prepend \&quo= t;2#\" (The yanked number will be perceived as binary.)
+If RADIX is 8, prepend \"8#\" (The yanked number will be perc= eived as octal.)
+If RADIX is 0, prepend \"10#\"= (The yanked number will be perceived as decimal.)
+If R= ADIX is 16, prepend \"16#\" (The yanked number will be perceived = as hexadecimal.) "
+ =C2=A0(interactive "P"= )
=C2=A0 =C2=A0(calc-wrapper
=C2=A0 =C2= =A0 (calc-pop-push-record-list
=C2=A0 =C2=A0 =C2=A00 "= ;yank"
- =C2=A0 =C2=A0(let ((thing (if (fboundp '= ;current-kill)
- =C2=A0 =C2=A0 (current-kill 0 t)
- =C2=A0 (car kill-ring-yank-pointe= r))))
+ =C2=A0 =C2=A0(let* ((radix-notation (cl-case radix=
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (2 "2#")
<= div class=3D"gmail_default" style=3D"">+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 (8 "8#")
+ =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 (0 "10#")
+ =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 (6 "16#")
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (t &= quot;")))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (thing= (concat radix-notation
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(if (fboundp = 9;current-kill)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(current-= kill 0 t)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(car kill-ring-yank-poi= nter)))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0(if (eq (car-safe cal= c-last-kill) thing)
- =C2=A0(cdr calc-last-kill)
- (if (stringp thing)
-<= span class=3D"" style=3D"white-space:pre"> =C2=A0 =C2=A0(let ((val = (math-read-exprs (calc-clean-newlines thing))))
- =C2=A0 =C2=A0 =C2=A0(if (eq (car= -safe val) 'error)
= - =C2=A0(progn
- =C2=A0 =C2=A0(setq val (math-read-exprs thing))=
- =C2= =A0 =C2=A0(if (eq (car-safe val) 'error)
- (error "Bad format in yanked= data")
- = =C2=A0 =C2=A0 =C2=A0val))
- val))))))))
+ =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0(cdr calc-last-kill)
+ =C2=A0 =C2=A0 = =C2=A0 =C2=A0(if (stringp thing)
+ =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0(let ((val (math-read-exprs (calc-clean-newlines thing)= )))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(if = (eq (car-safe val) 'error)
+ =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(progn
+ =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(setq val (math-= read-exprs thing))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(if (eq (car-safe val) 'error)=
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0(error "Bad format in yanked data")
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0val))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0val))))))))
=C2=A0
= =C2=A0;;; The Calc set- and get-register commands are modified versions of = functions
=C2=A0;;; in register.el
--=C2= =A0
2.6.0.rc0.24.gec371ff

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

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

--<= br>Kaushal Modi
--001a113cd6d2a1d97b0521993b37--