-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathshowoff-mode.el
More file actions
185 lines (145 loc) · 6.12 KB
/
showoff-mode.el
File metadata and controls
185 lines (145 loc) · 6.12 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
;;; showoff-mode.el --- Major mode to edit showoff presentation files in Emacs
;; Copyright (C) 2010 Nick Parker
;; Version 0.1.0
;; Keywords: showoff presentation major mode
;; Author: Nick Parker <nickp@developernotes.com>
;; URL: http://github.com/developernotes/showoff-mode
;; This file is not part of GNU Emacs.
;; 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 2, 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, write to the Free Software
;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;;; Commentary
;; For commentary please see the README.org or
;; http://github.com/developernotes/showoff-mode#readme
;;; Installation
;; In your shell:
;; $ cd ~/.emacs.d/site-lisp
;; $ git clone git://github.com/developernotes/showoff-mode.git
;; In your emacs config:
;; (add-to-list 'load-path "~/.emacs.d/site-lisp/showoff-mode")
;; (require 'showoff-mode)
;; (add-to-list 'auto-mode-alist '("\\.md$" . showoff-mode))
;;; Thanks
(require 'font-lock)
(require 'cl)
(require 'markdown-mode)
(defconst showoff-mode-version "0.1.0"
"The version of this `showoff-mode'.")
(defgroup showoff nil
"A showoff major mode."
:group 'tools)
(defcustom showoff-serve-buffer-name "*showoff-serve*"
"The name of the buffer used for serving a showoff presentation"
:type 'string
:group 'showoff)
(defcustom showoff-browse-url "http://localhost:9090"
"The default URL to view the showoff presentation"
:type 'string
:group 'showoff)
(defcustom showoff-manifest-file "showoff.json"
"The manifest file for the showoff presentation"
:type 'string
:group 'showoff)
(defcustom showoff-default-folder "one"
"The name of the default presentation folder"
:type 'string
:group 'showoff)
(defcustom showoff-default-file "01_slide.md"
"The name of the default presentation file"
:type 'string
:group 'showoff)
(defvar showoff-use-file-cache t
"Should `showoff-goto-file' keep a local cache of files?")
(defvar showoff-project-files '()
"Used internally to cache the files in a project.")
(defvar showoff-completing-function-alist '((ido ido-completing-read)
(icicles icicle-completing-read)
(none completing-read))
"The function to call to read file names from the user")
(defvar showoff-completing-library 'ido
"The library `showoff-goto-file' should use for
completing filenames (`ido' by default)")
(defvar showoff-mode-map (make-keymap)
"Keymap for showoff major mode.")
(defun showoff-add-slide (slide)
"Inserts a new slide at the given point"
(interactive "s Name of slide: ")
(insert (format "!SLIDE\n# %s #" slide)))
(defun showoff-view-manifest ()
"View the manifest file for the showoff presentation"
(interactive)
(find-file (concat (showoff-root) showoff-manifest-file)))
(defun showoff-serve ()
"Starts an HTTP server to run the presentation"
(interactive)
(save-excursion
(let ((root (showoff-root)))
(if root
(progn
(cd root)
(async-shell-command "showoff serve" showoff-serve-buffer-name))))))
(defun showoff-view-presentation ()
"Open browser to view the presentation"
(interactive)
(if (get-buffer showoff-serve-buffer-name)
(browse-url showoff-browse-url)
(progn
(showoff-serve)
(browse-url showoff-browse-url))))
(defun showoff-create-presentation (project directory)
"Creates a new showoff presentation"
(interactive "s Name of project: \nD Directory to create showoff presentation: ")
(cd directory)
(shell-command-to-string (format "showoff create %s" project))
(find-file (format "%s/%s/%s/%s" directory project showoff-default-folder showoff-default-file)))
(defun showoff-goto-file ()
"Uses your completing read to quickly jump to a showoff file in a project"
(interactive)
(let ((root (showoff-root)))
(find-file
(concat
(showoff-completing-read
"Find file: "
(showoff-cached-project-files root))))))
(defun showoff-cached-project-files (&optional root)
"Finds and caches all files in a given project."
(cond
((null showoff-use-file-cache) (showoff-project-files root))
((equal (showoff-root) (car showoff-project-files))
(cdr showoff-project-files))
(t (cdr (setq showoff-project-files
`(,root . ,(showoff-project-files root)))))))
(defun showoff-project-files (root)
"Finds all files in a given project."
(split-string
(shell-command-to-string (format "find %s -name \"*.md\" -type f" root))
"\n" t))
(defun showoff-completing-read (&rest args)
"Uses `showoff-completing-function-alist' to call the appropriate completing
function."
(let ((reading-fn
(cadr (assoc showoff-completing-library
showoff-completing-function-alist))))
(apply (symbol-function reading-fn) args)))
(defun showoff-root ()
(let ((root (locate-dominating-file default-directory showoff-manifest-file)))
(if root
(expand-file-name root)
(message "You don't appear to be in a showoff directory.") nil)))
(define-derived-mode showoff-mode markdown-mode
"showoff-mode"
"Major mode for editing showoff presentations...")
(define-key showoff-mode-map (kbd "C-c ;a") 'showoff-add-slide)
(define-key showoff-mode-map (kbd "C-c ;m") 'showoff-view-manifest)
(define-key showoff-mode-map (kbd "C-c ;s") 'showoff-serve)
(define-key showoff-mode-map (kbd "C-c ;v") 'showoff-view-presentation)
(define-key showoff-mode-map (kbd "C-c ;f") 'showoff-goto-file)
(provide 'showoff-mode)