From 26b75b456e536c1fb2d3979e07e82455b2d9c1ca Mon Sep 17 00:00:00 2001 From: Jay Belanger Date: Thu, 19 Dec 2013 22:53:24 -0600 Subject: [PATCH] lisp/calc/calc.el (calc-enter, calc-pop): Use the variable `calc-context-sensitive-enter'. doc/misc/calc.texi (Stack Manipulation Commands): Mention using the variable `calc-context-sensitive-enter' for `calc-enter' and `calc-pop'. --- doc/misc/ChangeLog | 5 ++++ doc/misc/calc.texi | 24 +++++++++++---- lisp/ChangeLog | 5 ++++ lisp/calc/calc.el | 73 +++++++++++++++++++++++++--------------------- 4 files changed, 69 insertions(+), 38 deletions(-) diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog index 8db1f7fa23b..fc07ad6dc08 100644 --- a/doc/misc/ChangeLog +++ b/doc/misc/ChangeLog @@ -1,3 +1,8 @@ +2013-12-20 Jay Belanger + + * calc.texi (Stack Manipulation Commands): Mention using the variable + `calc-context-sensitive-enter' for `calc-enter' and `calc-pop'. + 2013-12-12 Michael Albinus * tramp.texi (direntry): Use ssh but rsh. diff --git a/doc/misc/calc.texi b/doc/misc/calc.texi index 0154c82750a..425cd349784 100644 --- a/doc/misc/calc.texi +++ b/doc/misc/calc.texi @@ -11801,6 +11801,18 @@ Thus @kbd{M-@key{DEL}} by itself removes the second-from-top stack element, leaving the first, third, fourth, and so on; @kbd{M-3 M-@key{DEL}} deletes the third stack element. +The above commands do not depend on the location of the cursor. +If the customizable variable @code{calc-context-sensitive-enter} is +non-@code{nil} (@pxref{Customizing Calc}), these commands will become +context sensitive. For example, instead of duplicating the top of the stack, +@key{RET} will copy the element at the cursor to the top of the +stack. With a positive numeric prefix, a copy of the element at the +cursor and the appropriate number of preceding elements will be placed +at the top of the stack. A negative prefix will still duplicate the +specified element of the stack regardless of the cursor position. +Similarly, @key{DEL} will remove the corresponding elements from the +stack. + @kindex @key{TAB} @pindex calc-roll-down To exchange the top two elements of the stack, press @key{TAB} @@ -35697,11 +35709,13 @@ is @code{nil}. @end defvar @defvar calc-context-sensitive-enter -The command @code{calc-enter} will typically duplicate the top of the -stack. If @code{calc-context-sensitive-enter} is non-@code{nil}, -then the @code{calc-enter} will copy the element at the cursor to the -top of the stack. The default value of -@code{calc-context-sensitive-enter} is @code{nil}. +The commands @code{calc-enter} and @code{calc-pop} will typically +duplicate the top of the stack. If +@code{calc-context-sensitive-enter} is non-@code{nil}, then the +@code{calc-enter} will copy the element at the cursor to the +top of the stack and @code{calc-pop} will delete the element at the +cursor. The default value of @code{calc-context-sensitive-enter} is +@code{nil}. @end defvar @defvar calc-undo-length diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 464a3b11ce8..b502aa946ad 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2013-12-20 Jay Belanger + + * calc/calc.el (calc-enter, calc-pop): Use the variable + `calc-context-sensitive-enter'. + 2013-12-20 Lars Magne Ingebrigtsen * net/shr.el (shr-insert): Protect against infloops in degenerate diff --git a/lisp/calc/calc.el b/lisp/calc/calc.el index 72d456957c7..64549268e6e 100644 --- a/lisp/calc/calc.el +++ b/lisp/calc/calc.el @@ -429,7 +429,8 @@ when converting units." (defcustom calc-context-sensitive-enter nil - "If non-nil, the stack element under the cursor will be copied by `calc-enter'." + "If non-nil, the stack element under the cursor will be copied by `calc-enter' +and deleted by `calc-pop'." :group 'calc :version "24.4" :type 'boolean) @@ -2259,41 +2260,47 @@ the United States." (defun calc-enter (n) (interactive "p") - (calc-wrapper - (cond ((< n 0) - (calc-push-list (calc-top-list 1 (- n)))) - ((= n 0) - (calc-push-list (calc-top-list (calc-stack-size)))) - (t - (if (not calc-context-sensitive-enter) - (calc-push-list (calc-top-list n)) - (let ((num (max 1 (calc-locate-cursor-element (point))))) - (calc-push-list (calc-top-list n num)))))))) + (let ((num (if calc-context-sensitive-enter (max 1 (calc-locate-cursor-element (point)))))) + (calc-wrapper + (cond ((< n 0) + (calc-push-list (calc-top-list 1 (- n)))) + ((= n 0) + (calc-push-list (calc-top-list (calc-stack-size)))) + (num + (calc-push-list (calc-top-list n num))) + (t + (calc-push-list (calc-top-list n))))) + (if (and calc-context-sensitive-enter (> n 0)) (calc-cursor-stack-index (+ num n))))) (defun calc-pop (n) (interactive "P") - (calc-wrapper - (let* ((nn (prefix-numeric-value n)) - (top (and (null n) (calc-top 1)))) - (cond ((and (null n) - (eq (car-safe top) 'incomplete) - (> (length top) (if (eq (nth 1 top) 'intv) 3 2))) - (calc-pop-push-list 1 (let ((tt (copy-sequence top))) - (setcdr (nthcdr (- (length tt) 2) tt) nil) - (list tt)))) - ((< nn 0) - (if (and calc-any-selections - (calc-top-selected 1 (- nn))) - (calc-delete-selection (- nn)) - (calc-pop-stack 1 (- nn) t))) - ((= nn 0) - (calc-pop-stack (calc-stack-size) 1 t)) - (t - (if (and calc-any-selections - (= nn 1) - (calc-top-selected 1 1)) - (calc-delete-selection 1) - (calc-pop-stack nn))))))) + (let ((num (if calc-context-sensitive-enter (max 1 (calc-locate-cursor-element (point)))))) + (calc-wrapper + (let* ((nn (prefix-numeric-value n)) + (top (and (null n) (calc-top 1)))) + (cond ((and calc-context-sensitive-enter (> num 1)) + (calc-pop-stack nn num)) + ((and (null n) + (eq (car-safe top) 'incomplete) + (> (length top) (if (eq (nth 1 top) 'intv) 3 2))) + (calc-pop-push-list 1 (let ((tt (copy-sequence top))) + (setcdr (nthcdr (- (length tt) 2) tt) nil) + (list tt)))) + ((< nn 0) + (if (and calc-any-selections + (calc-top-selected 1 (- nn))) + (calc-delete-selection (- nn)) + (calc-pop-stack 1 (- nn) t))) + ((= nn 0) + (calc-pop-stack (calc-stack-size) 1 t)) + (t + (if (and calc-any-selections + (= nn 1) + (calc-top-selected 1 1)) + (calc-delete-selection 1) + (calc-pop-stack nn)))))) + (if calc-context-sensitive-enter (calc-cursor-stack-index (1- num))))) + -- 2.39.2