muse-protocols: Add DOI handling.
[muse-el.git] / lisp / muse-mode.el
blob83654cb17c00ea218f4b6198132fd797edc80b1b
1 ;;; muse-mode.el --- mode for editing Muse files; has font-lock support
3 ;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
5 ;; This file is not part of GNU Emacs.
7 ;; This is free software; you can redistribute it and/or modify it under
8 ;; the terms of the GNU General Public License as published by the Free
9 ;; Software Foundation; either version 2, or (at your option) any later
10 ;; version.
12 ;; This is distributed in the hope that it will be useful, but WITHOUT
13 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 ;; for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 ;; Boston, MA 02110-1301, USA.
22 ;;; Commentary:
24 ;; The Emacs Muse major mode is basically a hyped-up text-mode which
25 ;; knows a lot more about the apparent structure of the document.
27 ;;; Contributors:
29 ;; Andrea Riciputi (ariciputi AT pito DOT com) gave an initial
30 ;; implementation for tag completion by means of the `muse-insert-tag'
31 ;; function.
33 ;; Per B. Sederberg (per AT med DOT upenn DOT edu) contributed the
34 ;; insertion of relative links and list items.
36 ;;; Code:
38 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40 ;; Emacs Muse Major Mode
42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
44 (require 'muse)
45 (require 'muse-regexps)
46 (require 'muse-project)
47 (require 'muse-publish)
49 (autoload 'muse-use-font-lock "muse-colors")
51 (require 'derived)
52 (eval-when-compile
53 (condition-case nil
54 (require 'pcomplete) ; load if available
55 (error nil)))
57 ;;; Options:
59 (defgroup muse-mode nil
60 "Options controlling the behavior of the Muse editing Mode."
61 :group 'muse)
63 (defcustom muse-mode-highlight-p t
64 "If non-nil, highlight the content of Muse buffers."
65 :type 'boolean
66 :require 'muse-colors
67 :group 'muse-mode)
69 (defcustom muse-mode-auto-p nil
70 "If non-nil, automagically determine when Muse mode should be activated."
71 :type 'boolean
72 :set (function
73 (lambda (sym value)
74 (if value
75 (add-hook 'find-file-hooks 'muse-mode-maybe)
76 (remove-hook 'find-file-hooks 'muse-mode-maybe))
77 (set sym value)))
78 :group 'muse-mode)
80 (defcustom muse-mode-intangible-links nil
81 "If non-nil, use the intangible property on links.
82 This can cause problems with flyspell (and potentially fill-mode),
83 so only enable this if you don't use either of these."
84 :type 'boolean
85 :group 'muse-mode)
87 (defcustom muse-mode-hook nil
88 "A hook that is run when Muse mode is entered."
89 :type 'hook
90 :options '(flyspell-mode footnote-mode turn-on-auto-fill
91 highlight-changes-mode)
92 :set #'(lambda (sym val)
93 (when (featurep 'muse-wiki)
94 (add-to-list 'val 'muse-wiki-update-custom-values))
95 (set sym val))
96 :group 'muse-mode)
98 (defvar muse-mode-map
99 (let ((map (make-sparse-keymap)))
100 (define-key map [(control ?c) (control ?a)] 'muse-index)
101 (define-key map [(control ?c) (control ?b)] 'muse-browse-result)
102 (define-key map [(control ?c) (control ?c)] 'muse-follow-name-at-point)
103 (define-key map [(control ?c) (control ?e)] 'muse-edit-link-at-point)
104 (define-key map [(control ?c) (control ?t)] 'muse-publish-this-file)
105 (define-key map [(control ?c) (control ?v)] 'muse-follow-name-at-point)
107 (define-key map [(control ?c) (control ?l)] 'font-lock-mode)
109 (define-key map [(control ?c) ?=] 'muse-what-changed)
111 (define-key map [tab] 'muse-next-reference)
112 (define-key map [(control ?i)] 'muse-next-reference)
114 (if (featurep 'xemacs)
115 (progn
116 (define-key map [(button2)] 'muse-follow-name-at-mouse)
117 (define-key map [(shift button2)]
118 'muse-follow-name-at-mouse-other-window))
119 (define-key map [(shift control ?m)]
120 'muse-follow-name-at-point-other-window)
121 (define-key map [mouse-2] 'muse-follow-name-at-mouse)
122 (define-key map [(shift mouse-2)]
123 'muse-follow-name-at-mouse-other-window))
125 (define-key map [(shift tab)] 'muse-previous-reference)
126 (unless (featurep 'xemacs)
127 (define-key map [(shift iso-lefttab)] 'muse-previous-reference)
128 (define-key map [(shift control ?i)] 'muse-previous-reference))
130 (define-key map [(control ?c) (control ?f)] 'muse-project-find-file)
131 (define-key map [(control ?c) (control ?p)] 'muse-project-publish)
133 (define-key map [(control ?c) tab] 'muse-insert-tag)
134 (define-key map [(control ?c) (?i) (?t)] 'muse-insert-tag)
136 (define-key map [(control ?c) (?i) (?l)]
137 'muse-insert-relative-link-to-file)
139 ;; Enhanced link functions
140 (define-key map [(meta return)] 'muse-insert-list-item)
141 (define-key map [(control ?>)] 'muse-increase-list-item-indentation)
142 (define-key map [(control ?<)] 'muse-decrease-list-item-indentation)
144 (when (featurep 'pcomplete)
145 (define-key map [(meta tab)] 'pcomplete)
146 (define-key map [(meta control ?i)] 'pcomplete))
148 map)
149 "Keymap used by Emacs Muse mode.")
151 ;; Code:
153 ;;;###autoload
154 (define-derived-mode muse-mode text-mode "Muse"
155 "Muse is an Emacs mode for authoring and publishing documents.
156 \\{muse-mode-map}"
157 ;; Since we're not inheriting from normal-mode, we need to
158 ;; explicitly run file variables.
159 (condition-case err
160 (hack-local-variables)
161 (error (message "File local-variables error: %s"
162 (prin1-to-string err))))
163 ;; Avoid lock-up caused by use of the 'intangible' text property
164 ;; with flyspell.
165 (unless muse-mode-intangible-links
166 (set (make-local-variable 'inhibit-point-motion-hooks) t))
167 (setq muse-current-project (muse-project-of-file))
168 (muse-project-set-variables)
169 ;; Make sure several variables get updated if the user has changed
170 ;; them without using the customize interface.
171 (muse-update-ignored-extensions-regexp 'muse-ignored-extensions
172 muse-ignored-extensions)
173 (muse-update-url-regexp 'muse-url-protocols muse-url-protocols)
174 ;; Make fill not split up links
175 (when (boundp 'fill-nobreak-predicate)
176 (make-local-variable 'fill-nobreak-predicate)
177 ;; Work around annoying inconsistency in fill handling between
178 ;; Emacs 21 and 22.
179 (if (< emacs-major-version 22)
180 (setq fill-nobreak-predicate 'muse-mode-fill-nobreak-p)
181 (add-to-list 'fill-nobreak-predicate
182 'muse-mode-fill-nobreak-p)))
183 ;; Make fill work nicely with item lists
184 (set (make-local-variable 'adaptive-fill-regexp)
185 "\\s-+\\(-\\|[0-9]+\\.\\)\\s-+\\|\\[[0-9]+\\]\\s-*\\|\\s-*")
186 (set (make-local-variable 'paragraph-start)
187 (concat paragraph-start "\\|\\s-+\\(-\\|[0-9]+\\.\\)\\s-+"
188 "\\|\\[[0-9]+\\]\\s-*"))
189 ;; Comment syntax is `; comment'
190 (set (make-local-variable 'comment-start)
191 "; ")
192 (set (make-local-variable 'comment-start-skip)
193 "^;\\s-+")
194 ;; If we're using Emacs21, this makes flyspell work like it should
195 (when (boundp 'flyspell-generic-check-word-p)
196 (set (make-local-variable 'flyspell-generic-check-word-p)
197 'muse-mode-flyspell-p))
198 ;; If pcomplete is available, set it up
199 (when (featurep 'pcomplete)
200 (set (make-local-variable 'pcomplete-default-completion-function)
201 'muse-mode-completions)
202 (set (make-local-variable 'pcomplete-command-completion-function)
203 'muse-mode-completions)
204 (set (make-local-variable 'pcomplete-parse-arguments-function)
205 'muse-mode-current-word))
206 (when muse-mode-highlight-p
207 (muse-use-font-lock)))
209 (put 'muse-mode
210 'flyspell-mode-predicate
211 'muse-mode-flyspell-p)
213 (defun muse-mode-fill-nobreak-p ()
214 "Return nil if we should allow a fill to occur at point.
215 Otherwise return non-nil.
217 This is used to keep long explicit links from being mangled by
218 fill mode."
219 (save-excursion
220 (save-match-data
221 (and (re-search-backward "\\[\\[\\|\\]\\]"
222 (line-beginning-position) t)
223 (string= (or (match-string 0) "")
224 "[[")))))
226 (defun muse-mode-flyspell-p ()
227 "Return non-nil if we should allow spell-checking to occur at point.
228 Otherwise return nil.
230 This is used to keep links from being improperly colorized by flyspell."
231 (save-match-data
232 (null (muse-link-at-point))))
234 (defun muse-mode-choose-mode ()
235 "Turn the proper Emacs Muse related mode on for this file."
236 (let ((project (muse-project-of-file)))
237 (funcall (or (and project (muse-get-keyword :major-mode (cadr project) t))
238 'muse-mode))))
240 (defun muse-mode-maybe ()
241 "Maybe turn Emacs Muse mode on for this file."
242 (let ((project (muse-project-of-file)))
243 (and project
244 (funcall (or (muse-get-keyword :major-mode (cadr project) t)
245 'muse-mode)))))
247 ;;; Enhanced list editing
249 (defun muse-on-blank-line ()
250 "See if point is on a blank line"
251 (save-excursion
252 (beginning-of-line)
253 (looking-at (concat "[" muse-regexp-blank "]?[\n]+"))))
255 (defun muse-get-paragraph-start ()
256 "Return the start of the current paragraph. This function will
257 return nil if there are no prior paragraphs and the beginning of
258 the line if point is on a blank line."
259 (let ((para-start (concat "[\n]+[" muse-regexp-blank "]?[\n]+")))
260 ;; search back to start of paragraph
261 (save-excursion
262 (save-match-data
263 (if (not (muse-on-blank-line))
264 (re-search-backward para-start nil t)
265 (line-beginning-position))))))
267 ;;;###autoload
268 (defun muse-insert-list-item ()
269 "Insert a list item at the current point, taking into account
270 your current list type and indentation level."
271 (interactive)
272 (let ((newitem " - ")
273 (itemno nil)
274 (pstart (muse-get-paragraph-start))
275 (list-item (format muse-list-item-regexp
276 (concat "[" muse-regexp-blank "]*"))))
277 ;; search backwards for start of current item
278 (save-excursion
279 (when (re-search-backward list-item pstart t)
280 ;; save the matching item
281 (setq newitem (match-string 0))
282 ;; see what type it is
283 (if (string-match "::" (match-string 0))
284 ;; is a definition, replace the term
285 (setq newitem (concat " "
286 (read-string "Term: ")
287 " :: "))
288 ;; see if it's a numbered list
289 (when (string-match "[0-9]+" newitem)
290 ;; is numbered, so increment
291 (setq itemno (1+
292 (string-to-number
293 (match-string 0 newitem))))
294 (setq newitem (replace-match
295 (number-to-string itemno)
296 nil nil newitem))))))
297 ;; insert the new item
298 (insert (concat "\n" newitem))))
300 (defun muse-alter-list-item-indentation (operation)
301 "Alter the indentation of the current list item.
302 Valid values of OPERATION are 'increase and 'decrease."
303 (let ((pstart (muse-get-paragraph-start))
304 (list-item (format muse-list-item-regexp
305 (concat "[" muse-regexp-blank "]*")))
306 beg move-func indent)
307 ;; search backwards until start of paragraph to see if we are on a
308 ;; current item
309 (save-excursion
310 (if (or (progn (goto-char (muse-line-beginning-position))
311 ;; we are on an item
312 (looking-at list-item))
313 ;; not on item, so search backwards
314 (re-search-backward list-item pstart t))
315 (let ((beg (point)))
316 ;; we are on an item
317 (setq indent (buffer-substring (match-beginning 0)
318 (match-beginning 1)))
319 (muse-forward-list-item (muse-list-item-type (match-string 1))
320 (concat " \\{0,"
321 (number-to-string (length indent))
322 "\\}"))
323 (save-restriction
324 (narrow-to-region beg (point))
325 (goto-char (point-min))
326 (let ((halt nil))
327 (while (< (point) (point-max))
328 ;; increase or decrease the indentation
329 (unless halt
330 (cond ((eq operation 'increase)
331 (insert " "))
332 ((eq operation 'decrease)
333 (if (looking-at " ")
334 ;; we have enough space, so delete it
335 (delete-region (match-beginning 0)
336 (match-end 0))
337 (setq halt t)))))
338 (forward-line 1)))))
339 ;; we are not on an item, so warn
340 (message "You are not on a list item.")))))
342 ;;;###autoload
343 (defun muse-increase-list-item-indentation ()
344 "Increase the indentation of the current list item."
345 (interactive)
346 (muse-alter-list-item-indentation 'increase))
348 ;;;###autoload
349 (defun muse-decrease-list-item-indentation ()
350 "Decrease the indentation of the current list item."
351 (interactive)
352 (muse-alter-list-item-indentation 'decrease))
354 ;;; Support page name completion using pcomplete
356 (defun muse-completions ()
357 "Return a list of possible completions names for this buffer."
358 (let ((project (muse-project-of-file)))
359 (if project
360 (while (pcomplete-here
361 (mapcar 'car (muse-project-file-alist project)))))))
363 (defun muse-current-word ()
364 (let ((end (point)))
365 (save-excursion
366 (save-restriction
367 (skip-chars-backward (concat "^\\[\n" muse-regexp-blank))
368 (narrow-to-region (point) end))
369 (pcomplete-parse-buffer-arguments))))
371 ;;; Navigate/visit links or URLs. Use TAB, S-TAB and RET (or mouse-2).
373 (defun muse-link-at-point (&optional pos)
374 "Return link text if a URL or link is at point."
375 (let ((case-fold-search nil)
376 (inhibit-point-motion-hooks t)
377 (here (or pos (point))))
378 ;; if we are using muse-colors, we can just use link properties to
379 ;; determine whether we are on a link
380 (if (featurep 'muse-colors)
381 (when (get-text-property here 'muse-link)
382 (save-excursion
383 (when (get-text-property (1- here) 'muse-link)
384 (goto-char (or (previous-single-property-change here 'muse-link)
385 (point-min))))
386 (if (looking-at muse-explicit-link-regexp)
387 (progn
388 (goto-char (match-beginning 1))
389 (muse-handle-explicit-link))
390 (muse-handle-implicit-link))))
391 ;; use fallback method to find a link
392 (when (or (null pos)
393 (and (char-after pos)
394 (not (eq (char-syntax (char-after pos)) ?\ ))))
395 (save-excursion
396 (goto-char here)
397 ;; check for explicit link here or before point
398 (if (or (looking-at muse-explicit-link-regexp)
399 (and
400 (re-search-backward "\\[\\[\\|\\]\\]"
401 (muse-line-beginning-position)
403 (string= (or (match-string 0) "") "[[")
404 (looking-at muse-explicit-link-regexp)))
405 (progn
406 (goto-char (match-beginning 1))
407 (muse-handle-explicit-link))
408 (goto-char here)
409 ;; check for bare URL or other link type
410 (skip-chars-backward (concat "^'\"<>{}(\n" muse-regexp-blank))
411 (and (looking-at muse-implicit-link-regexp)
412 (muse-handle-implicit-link))))))))
414 (defun muse-make-link (link &optional name)
415 "Return a link to LINK with NAME as the text."
416 (when (string-match muse-explicit-link-regexp link)
417 (unless name (setq name (match-string 2 link)))
418 (setq link (match-string 1 link)))
419 (if (and name
420 link
421 (not (string= name ""))
422 (not (string= link name)))
423 (concat "[[" (muse-link-escape link) "][" (muse-link-escape name) "]]")
424 (concat "[[" (muse-link-escape link) "]]")))
426 ;;;###autoload
427 (defun muse-insert-relative-link-to-file ()
428 "Insert a relative link to a file, with optional description,
429 at the current point."
430 ;; Perhaps the relative location should be configurable, so that the
431 ;; file search would start in the publshing directory and then
432 ;; insert the link relative to the publishing directory
433 (interactive)
434 (insert
435 (muse-make-link
436 (file-relative-name (read-file-name "Link: "))
437 (read-string "Text: "))))
439 ;;;###autoload
440 (defun muse-edit-link-at-point ()
441 "Edit the current link.
442 Do not rename the page originally referred to."
443 (interactive)
444 (if (muse-link-at-point)
445 (replace-match
446 (save-match-data
447 (muse-make-link
448 (read-string "Link: "
449 (muse-match-string-no-properties 1))
450 (read-string "Text: "
451 (muse-match-string-no-properties 2))))
452 t t)
453 (error "There is no valid link at point")))
455 (defun muse-visit-link-default (link &optional other-window)
456 "Visit the URL or link named by LINK.
457 If ANCHOR is specified, search for it after opening LINK.
459 This is the default function to call when visiting links; it is
460 used by `muse-visit-link' if you have not specified :visit-link
461 in `muse-project-alist'."
462 (if (string-match muse-url-regexp link)
463 (muse-browse-url link)
464 (let (anchor
465 base-buffer)
466 (when (string-match "#" link)
467 (setq anchor (substring link (match-beginning 0))
468 link (if (= (match-beginning 0) 0)
469 ;; If there is an anchor but no link, default
470 ;; to the current page.
472 (substring link 0 (match-beginning 0)))))
473 (when link
474 (setq base-buffer (get-buffer link))
475 (if (and base-buffer (not (buffer-file-name base-buffer)))
476 ;; If file is temporary (no associated file), just switch to
477 ;; the buffer
478 (if other-window
479 (switch-to-buffer-other-window base-buffer)
480 (switch-to-buffer base-buffer))
481 (let ((project (muse-project-of-file)))
482 (if project
483 (muse-project-find-file link project
484 (and other-window
485 'find-file-other-window))
486 (if other-window
487 (find-file-other-window link)
488 (find-file link))))))
489 (when anchor
490 (let ((pos (point)))
491 (goto-char (point-min))
492 (unless (re-search-forward (concat "^\\W*" (regexp-quote anchor)
493 "\\b")
494 nil t)
495 (goto-char pos)))))))
497 (defun muse-visit-link (link &optional other-window)
498 "Visit the URL or link named by LINK."
499 (let ((visit-link-function
500 (muse-get-keyword :visit-link (cadr (muse-project-of-file)) t)))
501 (if visit-link-function
502 (funcall visit-link-function link other-window)
503 (muse-visit-link-default link other-window))))
505 ;;;###autoload
506 (defun muse-browse-result (style &optional other-window)
507 "Visit the current page's published result."
508 (interactive (list (muse-publish-get-style) current-prefix-arg))
509 (setq style (muse-style style))
510 (let ((result-path
511 (muse-publish-output-file buffer-file-name
512 (muse-style-element :path style) style)))
513 (if (not (file-readable-p result-path))
514 (error "Cannot open output file '%s'" result-path)
515 (if other-window
516 (find-file-other-window result-path)
517 (let ((func (muse-style-element :browser style t)))
518 (if func
519 (funcall func result-path)
520 (message "The %s publishing style does not support browsing."
521 style)))))))
523 ;;;###autoload
524 (defun muse-follow-name-at-point (&optional other-window)
525 "Visit the link at point, or insert a newline if none is found."
526 (interactive "P")
527 (let ((link (muse-link-at-point)))
528 (if link
529 (muse-visit-link link other-window)
530 (error "There is no valid link at point"))))
532 ;;;###autoload
533 (defun muse-follow-name-at-point-other-window ()
534 "Visit the link at point in other window."
535 (interactive)
536 (muse-follow-name-at-point t))
538 (defun muse-follow-name-at-mouse (event &optional other-window)
539 "Visit the link at point, or yank text if none is found."
540 (interactive "eN")
541 (save-excursion
542 (cond ((fboundp 'event-window) ; XEmacs
543 (set-buffer (window-buffer (event-window event)))
544 (and (funcall (symbol-function 'event-point) event)
545 (goto-char (funcall (symbol-function 'event-point) event))))
546 ((fboundp 'posn-window) ; Emacs
547 (set-buffer (window-buffer (posn-window (event-start event))))
548 (goto-char (posn-point (event-start event)))))
549 (let ((link (muse-link-at-point)))
550 (if link
551 (muse-visit-link link other-window)
552 ;; Fall back to normal binding for this event
553 (call-interactively
554 (lookup-key (current-global-map) (this-command-keys)))))))
556 (defun muse-follow-name-at-mouse-other-window (event)
557 "Visit the link at point"
558 (interactive "e")
559 ;; throw away the old window position, since other-window will
560 ;; change it anyway
561 (select-window (car (cadr event)))
562 (muse-follow-name-at-mouse event t))
564 ;;;###autoload
565 (defun muse-next-reference ()
566 "Move forward to next Muse link or URL, cycling if necessary."
567 (interactive)
568 (let ((cycled 0) pos)
569 (save-excursion
570 (when (memq (get-text-property (point) 'face)
571 '(muse-link-face muse-bad-link-face))
572 (goto-char (or (next-single-property-change (point) 'face)
573 (point-max))))
574 (while (< cycled 2)
575 (let ((next (point)))
576 (if (while (and (null pos)
577 (setq next
578 (next-single-property-change
579 next 'face)))
580 (when (memq (get-text-property next 'face)
581 '(muse-link-face muse-bad-link-face))
582 (setq pos next)))
583 (setq cycled 2)
584 (goto-char (point-min))
585 (setq cycled (1+ cycled))))))
586 (if pos
587 (goto-char pos))))
589 ;;;###autoload
590 (defun muse-previous-reference ()
591 "Move backward to the next Muse link or URL, cycling if necessary.
592 This function is not entirely accurate, but it's close enough."
593 (interactive)
594 (let ((cycled 0) pos)
595 (save-excursion
596 (while (< cycled 2)
597 (let ((prev (point)))
598 (if (while (and (null pos)
599 (setq prev
600 (previous-single-property-change
601 prev 'face)))
602 (when (memq (get-text-property prev 'face)
603 '(muse-link-face muse-bad-link-face))
604 (setq pos prev)))
605 (setq cycled 2)
606 (goto-char (point-max))
607 (setq cycled (1+ cycled))))))
608 (if pos
609 (goto-char pos))))
611 ;;;###autoload
612 (defun muse-what-changed ()
613 "Show the unsaved changes that have been made to the current file."
614 (interactive)
615 (diff-backup buffer-file-name))
617 ;;; Generate an index of all known Muse pages
619 (defun muse-generate-index (&optional as-list exclude-private)
620 "Generate an index of all Muse pages."
621 (let ((index (muse-index-as-string as-list exclude-private)))
622 (with-current-buffer (get-buffer-create "*Muse Index*")
623 (erase-buffer)
624 (insert index)
625 (current-buffer))))
627 ;;;###autoload
628 (defun muse-index ()
629 "Display an index of all known Muse pages."
630 (interactive)
631 (message "Generating Muse index...")
632 (let ((project (muse-project)))
633 (with-current-buffer (muse-generate-index)
634 (goto-char (point-min))
635 (muse-mode)
636 (setq muse-current-project project)
637 (pop-to-buffer (current-buffer))))
638 (message "Generating Muse index...done"))
640 (defun muse-index-as-string (&optional as-list exclude-private exclude-current)
641 "Generate an index of all Muse pages.
642 If AS-LIST is non-nil, insert a dash and spaces before each item.
643 If EXCLUDE-PRIVATE is non-nil, exclude files that have private permissions.
644 If EXCLUDE-CURRENT is non-nil, exclude the current file from the output."
645 (let ((files (sort (copy-alist (muse-project-file-alist))
646 (function
647 (lambda (l r)
648 (string-lessp (car l) (car r)))))))
649 (when (and exclude-current (muse-page-name))
650 (setq files (delete (assoc (muse-page-name) files) files)))
651 (with-temp-buffer
652 (while files
653 (unless (and exclude-private
654 (muse-project-private-p (cdar files)))
655 (insert (if as-list " - " "") "[[" (caar files) "]]\n"))
656 (setq files (cdr files)))
657 (buffer-string))))
659 ;;; Insert tags interactively on C-c TAB
661 (defvar muse-tag-history nil
662 "List of recently-entered tags; used by `muse-insert-tag'.
663 If you want a tag to start as the default, you may manually set
664 this variable to a list.")
666 (defvar muse-custom-tags nil
667 "Keep track of any new tags entered in `muse-insert-tag'.
668 If there are (X)HTML tags that you use frequently with that
669 function, you might want to set this manually.")
671 ;;;###autoload
672 (defun muse-insert-tag (tag)
673 "Insert a tag interactively with a blank line after it."
674 (interactive
675 (list
676 (completing-read
677 (concat "Tag: "
678 (when muse-tag-history
679 (concat "(default: " (car muse-tag-history) ") ")))
680 (mapcar 'list (nconc (mapcar 'car muse-publish-markup-tags)
681 muse-custom-tags))
682 nil nil nil 'muse-tag-history
683 (car muse-tag-history))))
684 (when (equal tag "")
685 (setq tag (car muse-tag-history)))
686 (let ((tag-entry (assoc tag muse-publish-markup-tags))
687 (options ""))
688 ;; Add to custom list if no entry exists
689 (unless tag-entry
690 (add-to-list 'muse-custom-tags tag))
691 ;; Get option
692 (when (nth 2 tag-entry)
693 (setq options (read-string "Option: ")))
694 (unless (equal options "")
695 (setq options (concat " " options)))
696 ;; Insert the tag, closing if necessary
697 (when tag (insert (concat "<" tag options ">")))
698 (when (nth 1 tag-entry)
699 (insert (concat "\n\n</" tag ">\n"))
700 (forward-line -2))))
702 (provide 'muse-mode)
704 ;;; muse-mode.el ends here