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}
@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
(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)
(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)))))
+