-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaph-ielm.el
executable file
·76 lines (57 loc) · 2.46 KB
/
aph-ielm.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
;;; aph-ielm.el --- Extensions for `ielm' -*- lexical-binding: t; -*-
;; Copyright (C) 2016 Aaron Harris
;; Author: Aaron Harris <[email protected]>
;; Keywords: tools, lisp
;; Dependencies: `ielm'
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Commands for use with `ielm'.
;;; Code:
(require 'ielm)
;;;; Subroutines
;;==============
(defun aph/ielm-get-last-output (&optional arg)
"Return the last output produced by `ielm'.
With argument N > 0, instead return the Nth last output.
With argument N < 0, return the Nth output since last clear.
With argument N = 0, do nothing and return nil.
If N greater in absolute value than the number of uncleared
outputs in the ielm buffer, return nil."
(let* ((arg (or arg 1))
(output-regexp (concat "^" ielm-prompt ".+\n"
"\\(?:\s.+\n\\)*"
"\\([^\s].+\\)"))
(search-function (if (< arg 0)
#'search-forward-regexp
#'search-backward-regexp)))
(unless (zerop arg)
(with-current-buffer "*ielm*"
(save-excursion
(goto-char (if (> arg 0) (point-max) (point-min)))
(if (funcall search-function output-regexp nil :noerror (abs arg))
(match-string 1)
nil))))))
;;;; Commands
;;===========
;;;###autoload
(defun aph/ielm-copy-last-output (&optional arg)
"Copy the last output produced by `ielm' to the kill ring.
With argument N > 0, instead copy the Nth last output.
With argument N < 0, copy the Nth output since last clear.
With argument N = 0, do nothing.
Return the newly copied string, or nil if nothing was
copied (e.g., if the argument is greater than the number of
uncleared outputs)."
(interactive "p")
(kill-new (aph/ielm-get-last-output arg)))
(provide 'aph-ielm)
;;; aph-ielm.el ends here