calc-trail.el 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. ;;; calc-trail.el --- functions for manipulating the Calc "trail"
  2. ;; Copyright (C) 1990-1993, 2001-2012 Free Software Foundation, Inc.
  3. ;; Author: David Gillespie <daveg@synaptics.com>
  4. ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;;; Code:
  18. ;; This file is autoloaded from calc-ext.el.
  19. (require 'calc-ext)
  20. (require 'calc-macs)
  21. ;;; Trail commands.
  22. (defun calc-trail-in ()
  23. (interactive)
  24. (let ((win (get-buffer-window (calc-trail-display t))))
  25. (and win (select-window win))))
  26. (defun calc-trail-out ()
  27. (interactive)
  28. (calc-select-buffer)
  29. (let ((win (get-buffer-window (current-buffer))))
  30. (if win
  31. (progn
  32. (select-window win)
  33. (calc-align-stack-window))
  34. (calc))))
  35. (defun calc-trail-next (n)
  36. (interactive "p")
  37. (calc-with-trail-buffer
  38. (forward-line n)
  39. (calc-trail-here)))
  40. (defun calc-trail-previous (n)
  41. (interactive "p")
  42. (calc-with-trail-buffer
  43. (forward-line (- n))
  44. (calc-trail-here)))
  45. (defun calc-trail-first (n)
  46. (interactive "p")
  47. (calc-with-trail-buffer
  48. (goto-char (point-min))
  49. (forward-line n)
  50. (calc-trail-here)))
  51. (defun calc-trail-last (n)
  52. (interactive "p")
  53. (calc-with-trail-buffer
  54. (goto-char (point-max))
  55. (forward-line (- n))
  56. (calc-trail-here)))
  57. (defun calc-trail-scroll-left (n)
  58. (interactive "P")
  59. (let ((curwin (selected-window)))
  60. (calc-with-trail-buffer
  61. (unwind-protect
  62. (progn
  63. (select-window (get-buffer-window (current-buffer)))
  64. (calc-scroll-left n))
  65. (select-window curwin)))))
  66. (defun calc-trail-scroll-right (n)
  67. (interactive "P")
  68. (let ((curwin (selected-window)))
  69. (calc-with-trail-buffer
  70. (unwind-protect
  71. (progn
  72. (select-window (get-buffer-window (current-buffer)))
  73. (calc-scroll-right n))
  74. (select-window curwin)))))
  75. (defun calc-trail-forward (n)
  76. (interactive "p")
  77. (calc-with-trail-buffer
  78. (forward-line (* n (1- (window-height))))
  79. (calc-trail-here)))
  80. (defun calc-trail-backward (n)
  81. (interactive "p")
  82. (calc-with-trail-buffer
  83. (forward-line (- (* n (1- (window-height)))))
  84. (calc-trail-here)))
  85. (defun calc-trail-isearch-forward ()
  86. (interactive)
  87. (calc-with-trail-buffer
  88. (let ((win (get-buffer-window (current-buffer)))
  89. pos)
  90. (save-window-excursion
  91. (select-window win)
  92. (isearch-forward)
  93. (setq pos (point)))
  94. (goto-char pos)
  95. (set-window-point win pos)
  96. (calc-trail-here))))
  97. (defun calc-trail-isearch-backward ()
  98. (interactive)
  99. (calc-with-trail-buffer
  100. (let ((win (get-buffer-window (current-buffer)))
  101. pos)
  102. (save-window-excursion
  103. (select-window win)
  104. (isearch-backward)
  105. (setq pos (point)))
  106. (goto-char pos)
  107. (set-window-point win pos)
  108. (calc-trail-here))))
  109. (defun calc-trail-yank (arg)
  110. (interactive "P")
  111. (calc-wrapper
  112. (or arg (calc-set-command-flag 'hold-trail))
  113. (calc-enter-result 0 "yank"
  114. (calc-with-trail-buffer
  115. (if arg
  116. (forward-line (- (prefix-numeric-value arg))))
  117. (if (or (looking-at "Emacs Calc")
  118. (looking-at "----")
  119. (looking-at " ? ? ?[^ \n]* *$")
  120. (looking-at "..?.?$"))
  121. (error "Can't yank that line"))
  122. (if (looking-at ".*, \\.\\.\\., ")
  123. (error "Can't yank (vector was abbreviated)"))
  124. (forward-char 4)
  125. (search-forward " ")
  126. (let* ((next (save-excursion (forward-line 1) (point)))
  127. (str (buffer-substring (point) (1- next)))
  128. (val (with-current-buffer save-buf
  129. (math-read-plain-expr str))))
  130. (if (eq (car-safe val) 'error)
  131. (error "Can't yank that line: %s" (nth 2 val))
  132. val))))))
  133. (defun calc-trail-marker (str)
  134. (interactive "sText to insert in trail: ")
  135. (calc-with-trail-buffer
  136. (forward-line 1)
  137. (let ((buffer-read-only nil))
  138. (insert "---- " str "\n"))
  139. (forward-line -1)
  140. (calc-trail-here)))
  141. (defun calc-trail-kill (n)
  142. (interactive "p")
  143. (calc-with-trail-buffer
  144. (let ((buffer-read-only nil))
  145. (save-restriction
  146. (narrow-to-region ; don't delete "Emacs Trail" header
  147. (save-excursion
  148. (goto-char (point-min))
  149. (forward-line 1)
  150. (point))
  151. (point-max))
  152. (kill-line n)))
  153. (calc-trail-here)))
  154. (provide 'calc-trail)
  155. ;;; calc-trail.el ends here