-
Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathmerlin-iedit.el
66 lines (57 loc) · 2.4 KB
/
merlin-iedit.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
;;; merlin-iedit.el --- Merlin and iedit integration -*- coding: utf-8; lexical-binding: t -*-
;; Licensed under the MIT license.
;; Author: Simon Castellan <simon.castellan(_)iuwt.fr>
;; Frédéric Bour <frederic.bour(_)lakaban.net>
;; Thomas Refis <thomas.refis(_)gmail.com>
;; Created: 27 June 2014
;; Version: 0.1
;; Keywords: ocaml languages
;; Package-Requires: ((emacs "25.1") (merlin "3") (iedit "0.9"))
;; URL: http://github.com/ocaml/merlin
;;; Commentary:
;; Provides the command `merlin-iedit-occurrences', which allows the
;; user to edit all the occurrences of the identifier at point using
;; `iedit'.
;;; Code:
(require 'merlin)
(require 'cl-lib)
(require 'iedit)
(defun merlin-iedit--printable (&rest _args)
"Stub substituting `iedit-printable' during merlin-iedit-occurrences."
"merlin-iedit-occurrences")
(defun merlin-iedit--make-occurrences-overlays (occurrences)
"Stub substituting `iedit-make-occurrences-overlays' during
merlin-iedit-occurrences."
(setq iedit-aborting nil)
(setq iedit-occurrences-overlays nil)
(setq iedit-read-only-occurrences-overlays nil)
(save-excursion
(save-window-excursion
(dolist (pos occurrences)
(let* ((start (assoc 'start pos))
(end (assoc 'end pos))
(beginning (merlin-make-point start))
(ending (merlin-make-point end)))
(if (text-property-not-all beginning ending 'read-only nil)
(push (iedit-make-read-only-occurrence-overlay beginning ending)
iedit-read-only-occurrences-overlays)
(push (iedit-make-occurrence-overlay beginning ending)
iedit-occurrences-overlays))))))
(length occurrences))
;;;###autoload
(defun merlin-iedit-occurrences ()
"Edit occurrences of identifier under cursor using `iedit'."
(interactive)
(if iedit-mode (iedit-mode -1)
(let ((r (merlin-call "occurrences"
"-identifier-at" (merlin-unmake-point (point)))))
(when r
(if (listp r)
(cl-letf (((symbol-function 'iedit-printable) #'merlin-iedit--printable)
((symbol-function 'iedit-make-occurrences-overlays)
(lambda (a _b _c)
(merlin-iedit--make-occurrences-overlays a))))
(iedit-start r (point-min) (point-max)))
(message r))))))
(provide 'merlin-iedit)
;;; merlin-iedit.el ends here