/usr/share/emacs/site-lisp/rabbit/rabbit-mode.el is in rabbit-mode 2.1.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | ;;; -*- mode: Emacs-Lisp; indent-tabs-mode: nil -*-
;;; rabbit-mode.el
;; Emacs major mode for Rabbit
;;; Copyright (c) 2006 - 2008 Atsushi TAKEDA <tkdats@kono.cis.iwate-u.ac.jp>
;;; Copyright (c) 2009 Kouhei Sutou <kou@cozmixng.org>
;;; $Id$
(require 'cl)
(require 'rd-mode)
(defvar rabbit-mode-hook nil
"Hooks run when entering `rabbit-mode' major mode")
(defvar rabbit-command "rabbit")
(defvar rabbit-command-command "rabbit-command")
(defvar rabbit-output-buffer nil)
(defvar rabbit-author nil)
(defvar rabbit-institution nil)
(defvar rabbit-theme "rabbit")
(defvar rabbit-title-metadata
'("subtitle" "content_source" "author" "institution" "theme"))
(defvar rabbit-slide-header-regexp "^=[ \t]*\\(.*\\)")
(defvar rabbit-heading-face 'font-lock-keyword-face)
(defvar rabbit-emphasis-face 'font-lock-function-name-face)
(defvar rabbit-verbatim-face 'font-lock-function-name-face)
(defvar rabbit-term-face 'font-lock-function-name-face)
(defvar rabbit-footnote-face 'font-lock-function-name-face)
(defvar rabbit-link-face 'font-lock-function-name-face)
(defvar rabbit-code-face 'font-lock-function-name-face)
(defvar rabbit-description-face 'font-lock-constant-face)
(defvar rabbit-comment-face 'font-lock-comment-face)
(defvar rabbit-keyboard-face 'font-lock-function-name-face)
(defvar rabbit-variable-face 'font-lock-function-name-face)
(defvar rabbit-font-lock-keywords
(list
'("^==+ .*$"
0 rabbit-comment-face)
`(,rabbit-slide-header-regexp
0 rabbit-heading-face)
'("((\\*[^*]*\\*+\\([^)*][^%]*\\*+\\)*))" ; ((* ... *))
0 rabbit-emphasis-face)
'("((%[^%]*%+\\([^)%][^%]*%+\\)*))" ; ((% ... %))
0 rabbit-keyboard-face)
'("((|[^|]*|+\\([^)|][^|]*|+\\)*))" ; ((| ... |))
0 rabbit-variable-face)
'("(('[^']*'+\\([^)'][^']*'+\\)*))" ; ((' ... '))
0 rabbit-verbatim-face)
'("((:[^:]*:+\\([^):][^:]*:+\\)*))" ; ((: ... :))
0 rabbit-term-face)
'("((-[^-]*-+\\([^)-][^-]*-+\\)*))" ; ((- ... -))
0 rabbit-footnote-face)
'("((<[^>]*>+\\([^)>][^>]*>+\\)*))" ; ((< ... >))
0 rabbit-link-face)
'("(({[^}]*}+\\([^)}][^}]*}+\\)*))" ; (({ ... }))
0 rabbit-code-face)
'("^:.*$"
0 rd-description-face)
'("^#.*$"
0 rabbit-comment-face)
))
(defvar rabbit-block-indent-size 2)
(defvar rabbit-image-size-unit-table
'(("relative")
("normalized")
("pixel")))
(defvar rabbit-default-image-size-unit
"relative")
(defvar rabbit-image-size-unit-history nil)
(define-derived-mode rabbit-mode rd-mode "Rabbit"
(setq comment-start "#")
(make-local-variable 'font-lock-defaults)
(setq font-lock-defaults '((rabbit-font-lock-keywords) t nil))
(make-local-variable 'font-lock-keywords)
(setq font-lock-keywords rabbit-font-lock-keywords)
(rabbit-setup-keys)
(run-hooks 'rabbit-mode-hook))
;;; interactive
(defun rabbit-run-rabbit ()
"Emacs major mode for rabbit."
(interactive)
(let ((filename (rabbit-buffer-filename))
(outbuf (rabbit-output-buffer)))
(set-buffer outbuf)
(if (get-buffer-process outbuf)
(error "Rabbit is already running")
(progn
(start-process "Rabbit" outbuf rabbit-command filename)
(if (one-window-p)
(set-window-buffer (split-window) outbuf)
(set-window-buffer (previous-window) outbuf))))))
;;; insert functions
(defun rabbit-insert-title-template (title)
"insert a title template."
(interactive "spresentation's title: ")
(insert (concat
(rabbit-join-without-empty-string
`(,(concat "= " title "\n")
,@(rabbit-make-metadata-strings))
"\n")
"\n")))
(defun rabbit-insert-image-template (file)
"insert a image template."
(interactive "fimage file: ")
(rabbit-insert-image-template-real file (rabbit-read-size-unit)))
(defun rabbit-insert-image-template-default (file)
"insert a image template with default image size unit."
(interactive "fimage file: ")
(rabbit-insert-image-template-real file))
(defun rabbit-insert-items ()
(interactive)
(let ((item (read-from-minibuffer "item: ")))
(unless (string-equal item "")
(insert (rabbit-block-indent (concat "* " item "\n")))
(rabbit-insert-items))))
;;; slide functions
(defun rabbit-insert-slide (slide-title)
"insert a slide."
(interactive "sslide title: ")
(insert (concat "= " slide-title "\n\n")))
(defun rabbit-delete-slide ()
"delete a current slide."
(interactive)
(rabbit-fancall-with-current-point 'delete-region))
(defun rabbit-copy-slide ()
"copy a current slide."
(interactive)
(rabbit-fancall-with-current-point 'kill-ring-save))
(defun rabbit-duplicate-slide ()
"copy a current slide and yank it as next slide."
(interactive)
(rabbit-copy-slide)
(rabbit-next-slide)
(yank))
;;; move functions
(defun rabbit-next-slide ()
"move to next slide."
(interactive)
(rabbit-forward-slide)
;; (forward-line 1)
;; (goto-char )
(recenter))
(defun rabbit-previous-slide ()
"move to previous slide."
(interactive)
(rabbit-backward-slide)
;; (goto-char )
(recenter))
(defun rabbit-remote (&rest args)
(shell-command-to-string
(mapconcat 'identity (cons rabbit-command-command args) " ")))
(defun rabbit-remote-next ()
"move to the next in Rabbit."
(interactive)
(rabbit-remote "--next-slide"))
(defun rabbit-remote-previous ()
"move to the previous in Rabbit."
(interactive)
(rabbit-remote "--previous"))
(defun rabbit-remote-next-slide ()
"move to the next slide in Rabbit."
(interactive)
(rabbit-remote "--next-slide"))
(defun rabbit-remote-previous-slide ()
"move to the previous slide in Rabbit."
(interactive)
(rabbit-remote "--previous-slide"))
(defun rabbit-remote-first-slide ()
"move to the first slide in Rabbit."
(interactive)
(rabbit-remote "--first-slide"))
(defun rabbit-remote-last-slide ()
"move to the last slide in Rabbit."
(interactive)
(rabbit-remote "--last-slide"))
(defun rabbit-remote-current-slide-rd ()
"get RD of the current slide in Rabbit."
(interactive)
(rabbit-remote "--current-slide-rd"))
(defun rabbit-remote-toggle-fullscreen ()
"toggle fullscreen in Rabbit."
(interactive)
(rabbit-remote "--toggle-fullscreen"))
(defun rabbit-remote-toggle-index-mode ()
"toggle index mode in Rabbit."
(interactive)
(rabbit-remote "--toggle-index-mode"))
(defun rabbit-remote-toggle-whiteout ()
"toggle whiteout in Rabbit."
(interactive)
(rabbit-remote "--toggle-whiteout"))
(defun rabbit-remote-toggle-blackout ()
"toggle blackout in Rabbit."
(interactive)
(rabbit-remote "--toggle-blackout"))
(defun rabbit-remote-quit ()
"quit Rabbit."
(interactive)
(rabbit-remote "--quit"))
;;; private
(defun rabbit-setup-keys ()
"define default key bindings."
(define-key rabbit-mode-map "\C-c\C-r" 'rabbit-run-rabbit)
(define-key rabbit-mode-map "\C-c\C-it" 'rabbit-insert-title-template)
(define-key rabbit-mode-map "\C-c\C-ii" 'rabbit-insert-image-template)
(define-key rabbit-mode-map "\C-c\C-is" 'rabbit-insert-slide)
(define-key rabbit-mode-map "\C-c\C-d" 'rabbit-delete-slide)
(define-key rabbit-mode-map "\M-n" 'rabbit-next-slide)
(define-key rabbit-mode-map "\M-p" 'rabbit-previous-slide))
(defun rabbit-make-metadata-strings ()
(let ((result '(""))
(rabbit-subtitle nil)
(rabbit-content_source nil))
(dolist (metadata rabbit-title-metadata (reverse result))
(let ((valuable (intern (concat "rabbit-" metadata))))
(if (eval valuable)
(setq result (cons (rabbit-metadata-string-template metadata
(eval valuable))
result))
(let ((value (read-from-minibuffer (concat metadata ": "))))
(if (string-equal value "")
""
(setq result (cons (rabbit-metadata-string-template metadata value)
result)))))))))
(defun rabbit-metadata-string-template (metadata value)
(concat ": " metadata "\n"
(rabbit-block-indent " ") value "\n"))
(defun rabbit-read-property (key)
"read `key' value from minibuf and return string as \"key = value\"
format if value is specified, otherwise return \"\"."
(let ((value (read-from-minibuffer (concat key ": "))))
(if (string-equal value "")
""
(concat key " = " value))))
(defun rabbit-block-indent (string)
(let ((indent ""))
(dotimes (i rabbit-block-indent-size (concat indent string))
(setq indent (concat indent " ")))))
(defun rabbit-read-block-property (key)
"read `key' value from minibuf and return string as \"key = value\"
format if value is specified, otherwise return \"\"."
(let ((property (rabbit-read-property key)))
(if (string-equal property "")
""
(rabbit-block-indent (concat "# " property)))))
(defun rabbit-buffer-filename ()
"return file name relating current buffer."
(or (buffer-file-name)
(error "This buffer is empty buffer")))
(defun rabbit-output-buffer ()
"return buffer for rabbit output."
(let* ((bufname (concat "*Rabbit<"
(file-relative-name (rabbit-buffer-filename))
">*"))
(buf (get-buffer-create bufname)))
buf))
(defun rabbit-read-size-unit ()
"read what unit use for image size."
(completing-read "image size unit: "
rabbit-image-size-unit-table
nil t nil
'rabbit-image-size-unit-history
rabbit-default-image-size-unit))
(defun rabbit-filter (predicate lst)
(let ((result '()))
(dolist (item lst (reverse result))
(unless (funcall predicate item)
(setq result (cons item result))))))
(defun rabbit-not-empty-string (string)
(and string (not (string-equal string ""))))
(defun rabbit-join-without-empty-string (strings separator)
(let ((result "")
(not-empty-strings (rabbit-filter
'(lambda (string)
(not (rabbit-not-empty-string string)))
strings)))
(if (null not-empty-strings)
""
(dolist (string (cdr not-empty-strings)
(concat (car not-empty-strings) result))
(setq result (concat result separator string))))))
(defun rabbit-insert-image-template-real (filename &optional unit)
"insert a image template."
(insert (concat
(rabbit-join-without-empty-string
`(,(rabbit-block-indent "# image")
,(rabbit-block-indent (concat "# src = "
(file-relative-name filename)))
,(rabbit-read-block-property "caption")
,@(rabbit-read-size-value
(or unit rabbit-default-image-size-unit)))
"\n")
"\n")))
(defun rabbit-read-size-value (unit)
"return strings that specify image size."
(let ((prefix (if (string-equal unit "pixel")
""
(concat unit "_"))))
(mapcar '(lambda (key)
(rabbit-read-block-property (concat prefix key)))
'("width" "height"))))
(defun rabbit-fancall-with-current-point (func)
(multiple-value-bind (beg end)
(rabbit-current-slide-point)
(funcall func beg end)))
(defun rabbit-current-slide-point ()
(values (save-excursion (rabbit-forward-slide)
(point))
(save-excursion (end-of-line)
(rabbit-backward-slide)
(point))))
(defun rabbit-forward-slide ()
(end-of-line)
(or (re-search-forward rabbit-slide-header-regexp nil t)
(end-of-buffer))
(beginning-of-line))
(defun rabbit-backward-slide ()
(or (re-search-backward rabbit-slide-header-regexp nil t)
(beginning-of-buffer)))
(provide 'rabbit-mode)
|