-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatlas.el
executable file
·52 lines (41 loc) · 1.7 KB
/
atlas.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
;;; atlas.el --- In-buffer map and reduce -*- lexical-binding: t; -*-
;; Copyright (C) 2016 Aaron Harris
;; Author: Aaron Harris <[email protected]>
;; Keywords: lisp
;; 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:
;; This module provides implementations of the basic tools of
;; functional programming (map and reduce) that operate over buffer
;; text.
;;
;; Functions provided are as follows:
;;
;; `atlas-map-lines':
;;
;; Map a function f over each line in the specified region,
;; replacing each line with its image under f.
;;; Code:
(defun atlas-map-lines (fun start end)
"Replace each line between START and END with result of FUN.
For each line between START and END, replace it with the result
of calling FUN (a function of one argument) with the text of that
line (as a string)."
(save-excursion
(save-restriction
(goto-char start)
(narrow-to-region start end)
(while (not (eobp))
(re-search-forward "^.*$")
(let ((line (match-string 0)))
(replace-match (save-match-data (funcall fun line))))))))
(provide 'atlas)
;;; atlas.el ends here