This repository has been archived by the owner on May 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
frame-workflow-editor.el
86 lines (70 loc) · 2.95 KB
/
frame-workflow-editor.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
77
78
79
80
81
82
83
84
85
86
;;; frame-workflow-editor.el --- Temporary buffer for editing a Lisp object -*- lexical-binding: t -*-
;; Copyright (C) 2018 by Akira Komamura
;; Author: Akira Komamura <akira.komamura@gmail.com>
;; Version: 0.1.0
;; Package-Requires: ((emacs "25.1"))
;; Keywords: convenience
;; URL: https://github.com/akirak/frame-workflow
;; This file is not part of GNU Emacs.
;;; License:
;; 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 library provides `frame-workflow-editor-popup' command which creates a
;; temporary buffer of `emacs-lisp-mode'.
;;; Code:
(defvar frame-workflow-editor-on-done)
(make-variable-buffer-local 'frame-workflow-editor-on-done)
(defvar frame-workflow-editor-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-c") #'frame-workflow-editor-done)
(define-key map (kbd "C-c C-k") #'frame-workflow-editor-cancel)
map)
"Keymap for `frame-workflow-editor-mode'.")
(define-derived-mode frame-workflow-editor-mode emacs-lisp-mode
"Major mode for editing a Lisp object or expression."
(use-local-map frame-workflow-editor-mode-map))
(defun frame-workflow-editor-popup (bufname insert-content on-done)
"Pop to a buffer for editing a Lisp expression.
BUFNAME is the name of a buffer. If there is a buffer of the same name, confirm
discarding it."
(declare (indent 1))
(catch 'abort
(let (buf)
(setq buf (get-buffer bufname))
(when (and buf (buffer-modified-p buf))
(if (yes-or-no-p (format "Buffer %s already exists and modified. Discard it?"
bufname))
(progn (kill-buffer buf)
(setq buf nil))
(pop-to-buffer buf)
(throw 'abort 'conflict)))
(with-current-buffer (or buf (generate-new-buffer bufname))
(erase-buffer)
(kill-all-local-variables)
(funcall insert-content)
(set-buffer-modified-p nil)
(frame-workflow-editor-mode)
(setq frame-workflow-editor-on-done on-done)
(setq-local header-line-format " C-c C-c to save, C-c C-k to cancel")
(pop-to-buffer (current-buffer))))))
(defun frame-workflow-editor-done ()
(interactive)
(funcall frame-workflow-editor-on-done)
(kill-buffer))
(defun frame-workflow-editor-cancel ()
(interactive)
(message "Aborted")
(kill-buffer))
(provide 'frame-workflow-editor)
;;; frame-workflow-editor.el ends here