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 part of Emacs Muse. It is not part of GNU Emacs.
7 ;; Emacs Muse is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published
9 ;; by the Free Software Foundation; either version 2, or (at your
10 ;; option) any later version.
12 ;; Emacs Muse is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with Emacs Muse; 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.
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.
29 ;; Andrea Riciputi (ariciputi AT pito DOT com) gave an initial
30 ;; implementation for tag completion by means of the `muse-insert-tag'
33 ;; Per B. Sederberg (per AT med DOT upenn DOT edu) contributed the
34 ;; insertion of relative links and list items, backlink searching, and
35 ;; other things as well.
37 ;; Stefan Schlee (stefan_schlee AT yahoo DOT com) fixed a bug in
38 ;; muse-next-reference and muse-previous-reference involving links
39 ;; that begin at point 1.
43 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
45 ;; Emacs Muse Major Mode
47 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
50 (require 'muse-regexps
)
51 (require 'muse-project
)
53 (autoload 'muse-use-font-lock
"muse-colors")
54 (autoload 'muse-publish-this-file
"muse-publish")
55 (autoload 'muse-publish-get-style
"muse-publish")
56 (autoload 'muse-publish-output-file
"muse-publish")
61 (require 'pcomplete
) ; load if available
66 (defgroup muse-mode nil
67 "Options controlling the behavior of the Muse editing Mode."
70 (defcustom muse-mode-highlight-p t
71 "If non-nil, highlight the content of Muse buffers."
76 (defcustom muse-mode-auto-p nil
77 "If non-nil, automagically determine when Muse mode should be activated."
82 (add-hook 'find-file-hooks
'muse-mode-maybe
)
83 (remove-hook 'find-file-hooks
'muse-mode-maybe
))
87 (defun muse-mode-maybe-after-init ()
88 (when muse-mode-auto-p
89 (add-hook 'find-file-hooks
'muse-mode-maybe
)))
91 ;; If the user sets this value in their init file, make sure that
93 (add-hook 'after-init-hook
'muse-mode-maybe-after-init
)
95 (defcustom muse-mode-intangible-links nil
96 "If non-nil, use the intangible property on links.
97 This can cause problems with flyspell (and potentially fill-mode),
98 so only enable this if you don't use either of these."
102 (defcustom muse-mode-hook nil
103 "A hook that is run when Muse mode is entered."
105 :options
'(flyspell-mode footnote-mode turn-on-auto-fill
106 highlight-changes-mode
)
109 (defcustom muse-grep-command
110 "find %D -type f ! -name '*~' | xargs -I {} echo \\\"{}\\\" | xargs egrep -n -e \"%W\""
111 "The command to use when grepping for backlinks and other
112 searches through the muse projects. The string %D is replaced by
113 the directories from muse-project-alist, space-separated. The
114 string %W is replaced with the name of the muse page or whatever
115 else you are searching for. This command has been modified to
116 handle spaces in filenames, which were giving egrep a problem.
118 Note: We highly recommend using glimpse to search large projects.
119 To use glimpse, install and edit a file called .glimpse_exclude
120 in your home directory. Put a list of glob patterns in that file
121 to exclude Emacs backup files, etc. Then, run the indexer using:
123 glimpseindex -o <list of Wiki directories>
125 Once that's completed, customize this variable to have the
130 Your searches will go much, much faster, especially for very
131 large projects. Don't forget to add a user cronjob to update the
136 (defvar muse-insert-map
137 (let ((map (make-sparse-keymap)))
138 (define-key map
"l" 'muse-insert-relative-link-to-file
)
139 (define-key map
"t" 'muse-insert-tag
)
140 (define-key map
"u" 'muse-insert-url
)
144 (defvar muse-mode-map
145 (let ((map (make-sparse-keymap)))
146 (define-key map
[(control ?c
) (control ?a
)] 'muse-index
)
147 (define-key map
[(control ?c
) (control ?e
)] 'muse-edit-link-at-point
)
148 (define-key map
[(control ?c
) (control ?l
)] 'font-lock-mode
)
149 (define-key map
[(control ?c
) (control ?t
)]
150 'muse-project-publish-this-file
)
151 (define-key map
[(control ?c
) (control ?T
)] 'muse-publish-this-file
)
152 (define-key map
[(control ?c
) (control ?v
)] 'muse-browse-result
)
154 (define-key map
[(control ?c
) ?
=] 'muse-what-changed
)
156 (define-key map
[tab] 'muse-next-reference)
157 (define-key map [(control ?i)] 'muse-next-reference)
159 (if (featurep 'xemacs)
161 (define-key map [(button2)] 'muse-follow-name-at-mouse)
162 (define-key map [(shift button2)]
163 'muse-follow-name-at-mouse-other-window))
164 (define-key map [(shift control ?m)]
165 'muse-follow-name-at-point-other-window)
166 (define-key map [mouse-2] 'muse-follow-name-at-mouse)
167 (define-key map [(shift mouse-2)]
168 'muse-follow-name-at-mouse-other-window))
170 (define-key map [(shift tab)] 'muse-previous-reference)
171 (unless (featurep 'xemacs)
172 (define-key map [(shift iso-lefttab)] 'muse-previous-reference)
173 (define-key map [(shift control ?i)] 'muse-previous-reference))
175 (define-key map [(control ?c) (control ?f)] 'muse-project-find-file)
176 (define-key map [(control ?c) (control ?p)] 'muse-project-publish)
178 (define-key map [(control ?c) tab] 'muse-insert-thing)
180 ;; Searching functions
181 (define-key map [(control ?c) (control ?b)] 'muse-find-backlinks)
182 (define-key map [(control ?c) (control ?s)] 'muse-search)
184 ;; Enhanced list functions
185 (define-key map [(meta return)] 'muse-insert-list-item)
186 (define-key map [(control ?>)] 'muse-increase-list-item-indentation)
187 (define-key map [(control ?<)] 'muse-decrease-list-item-indentation)
189 (when (featurep 'pcomplete)
190 (define-key map [(meta tab)] 'pcomplete)
191 (define-key map [(meta control ?i)] 'pcomplete))
194 "Keymap used by Emacs Muse mode.")
199 (define-derived-mode muse-mode text-mode "Muse"
200 "Muse is an Emacs mode for authoring and publishing documents.
202 ;; Since we're not inheriting from normal-mode, we need to
203 ;; explicitly run file variables.
205 (hack-local-variables)
206 (error (message "File local-variables error: %s"
207 (prin1-to-string err))))
208 ;; Avoid lock-up caused by use of the 'intangible' text property
210 (unless muse-mode-intangible-links
211 (set (make-local-variable 'inhibit-point-motion-hooks) t))
212 (setq muse-current-project (muse-project-of-file))
213 (muse-project-set-variables)
214 ;; Make fill not split up links
215 (when (boundp 'fill-nobreak-predicate)
216 (make-local-variable 'fill-nobreak-predicate)
217 ;; Work around annoying inconsistency in fill handling between
219 (if (< emacs-major-version 22)
220 (setq fill-nobreak-predicate 'muse-mode-fill-nobreak-p)
221 (add-to-list 'fill-nobreak-predicate
222 'muse-mode-fill-nobreak-p)))
223 ;; Make fill work nicely with item lists
224 (set (make-local-variable 'adaptive-fill-regexp)
225 (concat "\\s-+\\(-\\|[0-9]+\\.\\)\\s-+\\|\\[[0-9]+\\]\\s-*"
226 "\\|.*\\s-*::\\s-+\\|\\s-*"))
227 (set (make-local-variable 'paragraph-start)
228 (concat paragraph-start
229 "\\|\\s-+\\(-\\|[0-9]+\\.\\)\\s-+\\|\\[[0-9]+\\]\\s-*"
230 "\\|.*\\s-*::\\s-+"))
231 ;; Comment syntax is `; comment'
232 (set (make-local-variable 'comment-start)
234 (set (make-local-variable 'comment-start-skip)
236 ;; If we're using Emacs21, this makes flyspell work like it should
237 (when (boundp 'flyspell-generic-check-word-p)
238 (set (make-local-variable 'flyspell-generic-check-word-p)
239 'muse-mode-flyspell-p))
240 ;; If pcomplete is available, set it up
241 (when (featurep 'pcomplete)
242 (set (make-local-variable 'pcomplete-default-completion-function)
243 'muse-mode-completions)
244 (set (make-local-variable 'pcomplete-command-completion-function)
245 'muse-mode-completions)
246 (set (make-local-variable 'pcomplete-parse-arguments-function)
247 'muse-mode-current-word))
248 ;; Initialize any auto-generated variables
249 (run-hooks 'muse-update-values-hook)
250 (when muse-mode-highlight-p
251 (muse-use-font-lock)))
254 'flyspell-mode-predicate
255 'muse-mode-flyspell-p)
257 (defun muse-mode-fill-nobreak-p ()
258 "Return nil if we should allow a fill to occur at point.
259 Otherwise return non-nil.
261 This is used to keep long explicit links from being mangled by
265 (and (re-search-backward "\\[\\[\\|\\]\\]"
266 (line-beginning-position) t)
267 (string= (or (match-string 0) "")
270 (defun muse-mode-flyspell-p ()
271 "Return non-nil if we should allow spell-checking to occur at point.
272 Otherwise return nil.
274 This is used to keep links from being improperly colorized by flyspell."
275 (and (not (get-text-property (if (bobp) (point) (1- (point)))
278 (null (muse-link-at-point)))))
281 (defun muse-mode-choose-mode ()
282 "Turn the proper Emacs Muse related mode on for this file."
283 (let ((project (muse-project-of-file)))
284 (funcall (or (and project (muse-get-keyword :major-mode (cadr project) t))
287 (defun muse-mode-maybe ()
288 "Maybe turn Emacs Muse mode on for this file."
289 (let ((project (muse-project-of-file)))
291 (funcall (or (muse-get-keyword :major-mode (cadr project) t)
294 ;;; Enhanced list editing
296 (defun muse-on-blank-line ()
297 "See if point is on a blank line"
300 (looking-at (concat "[" muse-regexp-blank "]?[\n]+"))))
302 (defun muse-get-paragraph-start ()
303 "Return the start of the current paragraph. This function will
304 return nil if there are no prior paragraphs and the beginning of
305 the line if point is on a blank line."
306 (let ((para-start (concat "[\n]+[" muse-regexp-blank "]?[\n]+")))
307 ;; search back to start of paragraph
310 (if (not (muse-on-blank-line))
311 (re-search-backward para-start nil t)
312 (line-beginning-position))))))
314 (defun muse-insert-thing ()
315 "Prompt for something to insert into the current buffer."
317 (message "Insert:\nl link\nt Muse tag\nu URL")
319 (let ((overriding-local-map muse-insert-map))
320 (setq key (read-key-sequence nil)))
321 (if (commandp (setq cmd (lookup-key muse-insert-map key)))
323 (call-interactively cmd))
324 (message "Not inserting anything"))))
327 (defun muse-insert-list-item ()
328 "Insert a list item at the current point, taking into account
329 your current list type and indentation level."
331 (let ((newitem " - ")
333 (pstart (muse-get-paragraph-start))
334 (list-item (format muse-list-item-regexp
335 (concat "[" muse-regexp-blank "]*"))))
336 ;; search backwards for start of current item
338 (when (re-search-backward list-item pstart t)
339 ;; save the matching item
340 (setq newitem (match-string 0))
341 ;; see what type it is
342 (if (string-match "::" (match-string 0))
343 ;; is a definition, replace the term
344 (setq newitem (concat " "
345 (read-string "Term: ")
347 ;; see if it's a numbered list
348 (when (string-match "[0-9]+" newitem)
349 ;; is numbered, so increment
352 (match-string 0 newitem))))
353 (setq newitem (replace-match
354 (number-to-string itemno)
355 nil nil newitem))))))
356 ;; insert the new item
357 (insert (concat "\n" newitem))))
359 (defun muse-alter-list-item-indentation (operation)
360 "Alter the indentation of the current list item.
361 Valid values of OPERATION are 'increase and 'decrease."
362 (let ((pstart (muse-get-paragraph-start))
363 (list-item (format muse-list-item-regexp
364 (concat "[" muse-regexp-blank "]*")))
365 beg move-func indent)
366 ;; search backwards until start of paragraph to see if we are on a
369 (if (or (progn (goto-char (muse-line-beginning-position))
371 (looking-at list-item))
372 ;; not on item, so search backwards
373 (re-search-backward list-item pstart t))
376 (setq indent (buffer-substring (match-beginning 0)
377 (match-beginning 1)))
378 (muse-forward-list-item (muse-list-item-type (match-string 1))
379 (concat "[" muse-regexp-blank "]*")
382 (narrow-to-region beg (point))
383 (goto-char (point-min))
385 (while (< (point) (point-max))
386 ;; increase or decrease the indentation
388 (cond ((eq operation 'increase)
390 ((eq operation 'decrease)
392 ;; we have enough space, so delete it
393 (delete-region (match-beginning 0)
397 ;; we are not on an item, so warn
398 (message "You are not on a list item.")))))
401 (defun muse-increase-list-item-indentation ()
402 "Increase the indentation of the current list item."
404 (muse-alter-list-item-indentation 'increase))
407 (defun muse-decrease-list-item-indentation ()
408 "Decrease the indentation of the current list item."
410 (muse-alter-list-item-indentation 'decrease))
412 ;;; Support page name completion using pcomplete
414 (defun muse-mode-completions ()
415 "Return a list of possible completions names for this buffer."
416 (let ((project (muse-project-of-file)))
418 (while (pcomplete-here
419 (mapcar 'car (muse-project-file-alist project)))))))
421 (defun muse-mode-current-word ()
425 (skip-chars-backward (concat "^\\[\n" muse-regexp-blank))
426 (narrow-to-region (point) end))
427 (pcomplete-parse-buffer-arguments))))
429 ;;; Navigate/visit links or URLs. Use TAB, S-TAB and RET (or mouse-2).
431 (defun muse-link-at-point (&optional pos)
432 "Return link text if a URL or link is at point."
433 (let ((case-fold-search nil)
434 (inhibit-point-motion-hooks t)
435 (here (or pos (point))))
436 ;; if we are using muse-colors, we can just use link properties to
437 ;; determine whether we are on a link
438 (if (featurep 'muse-colors)
439 (when (get-text-property here 'muse-link)
441 (when (and (not (bobp))
442 (get-text-property (1- here) 'muse-link))
443 (goto-char (or (previous-single-property-change here 'muse-link)
445 (if (looking-at muse-explicit-link-regexp)
447 (goto-char (match-beginning 1))
448 (muse-handle-explicit-link))
449 (muse-handle-implicit-link))))
450 ;; use fallback method to find a link
452 (and (char-after pos)
453 (not (eq (char-syntax (char-after pos)) ?\ ))))
456 ;; check for explicit link here or before point
457 (if (or (looking-at muse-explicit-link-regexp)
459 (re-search-backward "\\[\\[\\|\\]\\]"
460 (muse-line-beginning-position)
462 (string= (or (match-string 0) "") "[[")
463 (looking-at muse-explicit-link-regexp)))
465 (goto-char (match-beginning 1))
466 (muse-handle-explicit-link))
468 ;; check for bare URL or other link type
469 (skip-chars-backward (concat "^'\"<>{}(\n" muse-regexp-blank))
470 (and (looking-at muse-implicit-link-regexp)
471 (muse-handle-implicit-link))))))))
473 (defun muse-make-link (link &optional desc)
474 "Return a link to LINK with DESC as the description."
475 (when (string-match muse-explicit-link-regexp link)
476 (unless desc (setq desc (muse-get-link-desc link)))
477 (setq link (muse-get-link link)))
480 (not (string= desc ""))
481 (not (string= link desc)))
482 (concat "[[" (muse-link-escape link) "][" (muse-link-escape desc) "]]")
483 (concat "[[" (or (muse-link-escape link) "") "]]")))
486 (defun muse-insert-relative-link-to-file ()
487 "Insert a relative link to a file, with optional description, at point."
488 ;; Perhaps the relative location should be configurable, so that the
489 ;; file search would start in the publishing directory and then
490 ;; insert the link relative to the publishing directory
493 (muse-make-link (file-relative-name (read-file-name "Link: "))
494 (read-string "Text: "))))
496 (defun muse-insert-url ()
497 "Insert a URL, with optional description, at point."
500 (muse-make-link (read-string "URL: ")
501 (read-string "Text: "))))
504 (defun muse-edit-link-at-point ()
505 "Edit the current link.
506 Do not rename the page originally referred to."
508 (if (muse-link-at-point)
509 (let ((link (muse-link-unescape (muse-get-link)))
510 (desc (muse-link-unescape (muse-get-link-desc))))
514 (read-string "Link: " link)
515 (read-string "Text: " desc)))
517 (error "There is no valid link at point")))
519 (defun muse-visit-link-default (link &optional other-window)
520 "Visit the URL or link named by LINK.
521 If ANCHOR is specified, search for it after opening LINK.
523 This is the default function to call when visiting links; it is
524 used by `muse-visit-link' if you have not specified :visit-link
525 in `muse-project-alist'."
526 (if (string-match muse-url-regexp link)
527 (muse-browse-url link)
530 (when (string-match "#" link)
531 (setq anchor (substring link (match-beginning 0))
532 link (if (= (match-beginning 0) 0)
533 ;; If there is an anchor but no link, default
534 ;; to the current page.
536 (substring link 0 (match-beginning 0)))))
538 (setq base-buffer (get-buffer link))
539 (if (and base-buffer (not (buffer-file-name base-buffer)))
540 ;; If file is temporary (no associated file), just switch to
543 (switch-to-buffer-other-window base-buffer)
544 (switch-to-buffer base-buffer))
545 (let ((project (muse-project-of-file)))
547 (muse-project-find-file link project
549 'find-file-other-window))
551 (find-file-other-window link)
552 (find-file link))))))
555 (goto-char (point-min))
556 (unless (re-search-forward (concat "^\\W*" (regexp-quote anchor)
559 (goto-char pos)))))))
561 (defun muse-visit-link (link &optional other-window)
562 "Visit the URL or link named by LINK."
563 (let ((visit-link-function
564 (muse-get-keyword :visit-link (cadr (muse-project-of-file)) t)))
565 (if visit-link-function
566 (funcall visit-link-function link other-window)
567 (muse-visit-link-default link other-window))))
570 (defun muse-browse-result (style &optional other-window)
571 "Visit the current page's published result."
573 (list (muse-project-get-applicable-style buffer-file-name
574 (cddr muse-current-project))
576 (setq style (muse-style style))
578 (muse-publish-output-file buffer-file-name
579 (muse-style-element :path style) style)))
580 (if (not (file-readable-p result-path))
581 (error "Cannot open output file '%s'" result-path)
583 (find-file-other-window result-path)
584 (let ((func (muse-style-element :browser style t)))
586 (funcall func result-path)
587 (message "The %s publishing style does not support browsing."
591 (defun muse-follow-name-at-point (&optional other-window)
592 "Visit the link at point."
594 (let ((link (muse-link-at-point)))
596 (muse-visit-link link other-window)
597 (error "There is no valid link at point"))))
600 (defun muse-follow-name-at-point-other-window ()
601 "Visit the link at point in other window."
603 (muse-follow-name-at-point t))
605 (defun muse-follow-name-at-mouse (event &optional other-window)
606 "Visit the link at point, or yank text if none is found."
610 (cond ((fboundp 'event-window) ; XEmacs
611 (set-buffer (window-buffer (event-window event)))
612 (and (funcall (symbol-function 'event-point) event)
613 (goto-char (funcall (symbol-function 'event-point)
615 ((fboundp 'posn-window) ; Emacs
616 (set-buffer (window-buffer (posn-window (event-start event))))
617 (goto-char (posn-point (event-start event)))))
618 (let ((link (muse-link-at-point)))
620 (muse-visit-link link other-window)
622 ;; Fall back to normal binding for this event
624 (lookup-key (current-global-map) (this-command-keys)))))
626 (defun muse-follow-name-at-mouse-other-window (event)
627 "Visit the link at point"
629 ;; throw away the old window position, since other-window will
631 (select-window (car (cadr event)))
632 (muse-follow-name-at-mouse event t))
635 (defun muse-next-reference ()
636 "Move forward to next Muse link or URL, cycling if necessary."
640 (when (get-text-property (point) 'muse-link)
641 (goto-char (or (next-single-property-change (point) 'muse-link)
644 (setq pos (next-single-property-change (point) 'muse-link))
647 (if (get-text-property (point-min) 'muse-link)
648 (setq pos (point-min))
649 (setq pos (next-single-property-change (point-min) 'muse-link)))))
655 (defun muse-previous-reference ()
656 "Move backward to the next Muse link or URL, cycling if necessary.
657 In case of Emacs x <= 21 and ignoring of intangible properties (see
658 `muse-mode-intangible-links').
660 This function is not entirely accurate, but it's close enough."
665 ;; Hack: The user perceives the two cases of point ("|")
666 ;; position (1) "|[[" and (2) "[[|" or "][|" as "point is at
667 ;; start of link". But in the sense of the function
668 ;; "previous-single-property-change" these two cases are
669 ;; different. The following code aligns these two cases. Emacs
670 ;; 21: If the intangible property is ignored case (2) is more
671 ;; complicate and this hack only solves the problem partially.
673 (when (and (get-text-property (point) 'muse-link)
674 (muse-looking-back "\\[\\|\\]"))
675 (goto-char (or (previous-single-property-change (point) 'muse-link)
678 (when (eq (point) (point-min))
679 (goto-char (point-max)))
681 (setq pos (previous-single-property-change (point) 'muse-link))
684 (if (get-text-property (point-min) 'muse-link)
685 (setq pos (point-min))
686 (setq pos (previous-single-property-change (point-max)
690 (if (get-text-property pos 'muse-link)
692 (goto-char (or (previous-single-property-change pos 'muse-link)
696 (defun muse-what-changed ()
697 "Show the unsaved changes that have been made to the current file."
699 (diff-backup buffer-file-name))
702 ;;; Find text in project pages, or pages referring to the current page
704 (defvar muse-search-history nil)
706 (defun muse-grep (string &optional grep-command-no-shadow)
707 "Grep for STRING in the project directories.
708 GREP-COMMAND if passed will supplant `muse-grep-command'."
709 ;; careful - grep-command leaks into compile, so we call it
710 ;; -no-shadow instead
712 (let* ((str (or grep-command-no-shadow muse-grep-command))
713 (muse-directories (mapcar
717 (dirs (mapconcat (lambda (dir)
718 (shell-quote-argument
719 (expand-file-name dir)))
720 muse-directories " ")))
721 (while (string-match "%W" str)
722 (setq str (replace-match string t t str)))
723 (while (string-match "%D" str)
724 (setq str (replace-match dirs t t str)))
725 (if (fboundp 'compilation-start)
726 (compilation-start str nil (lambda (&rest args) "*search*")
728 (and (fboundp 'compile-internal)
729 (compile-internal str "No more search hits" "search"
730 nil grep-regexp-alist)))))
733 (defun muse-search-with-command (text)
734 "Search for the given TEXT string in the project directories
735 using the specified command."
737 (list (let ((str (concat muse-grep-command)) pos)
738 (when (string-match "%W" str)
739 (setq pos (match-beginning 0))
740 (unless (featurep 'xemacs)
742 (setq str (replace-match "" t t str)))
743 (read-from-minibuffer "Search command: "
744 (cons str pos) nil nil
745 'muse-search-history))))
746 (muse-grep nil text))
749 (defun muse-search ()
750 "Search for the given TEXT using the default grep command."
752 (muse-grep (read-string "Search: ")))
755 (defun muse-find-backlinks ()
756 "Grep for the current pagename in all the project directories."
758 (muse-grep (muse-page-name)))
761 ;;; Generate an index of all known Muse pages
763 (defun muse-generate-index (&optional as-list exclude-private)
764 "Generate an index of all Muse pages."
765 (let ((index (muse-index-as-string as-list exclude-private)))
766 (with-current-buffer (get-buffer-create "*Muse Index*")
773 "Display an index of all known Muse pages."
775 (message "Generating Muse index...")
776 (let ((project (muse-project)))
777 (with-current-buffer (muse-generate-index)
778 (goto-char (point-min))
780 (setq muse-current-project project)
781 (pop-to-buffer (current-buffer))))
782 (message "Generating Muse index...done"))
784 (defun muse-index-as-string (&optional as-list exclude-private exclude-current)
785 "Generate an index of all Muse pages.
786 If AS-LIST is non-nil, insert a dash and spaces before each item.
787 If EXCLUDE-PRIVATE is non-nil, exclude files that have private permissions.
788 If EXCLUDE-CURRENT is non-nil, exclude the current file from the output."
789 (let ((files (sort (copy-alist (muse-project-file-alist))
792 (string-lessp (car l) (car r)))))))
793 (when (and exclude-current (muse-page-name))
794 (setq files (delete (assoc (muse-page-name) files) files)))
797 (unless (and exclude-private
798 (muse-project-private-p (cdar files)))
799 (insert (if as-list " - " "") "[[" (caar files) "]]\n"))
800 (setq files (cdr files)))
803 ;;; Insert tags interactively on C-c TAB t
805 (defvar muse-tag-history nil
806 "List of recently-entered tags; used by `muse-insert-tag'.
807 If you want a tag to start as the default, you may manually set
808 this variable to a list.")
810 (defvar muse-custom-tags nil
811 "Keep track of any new tags entered in `muse-insert-tag'.
812 If there are (X)HTML tags that you use frequently with that
813 function, you might want to set this manually.")
816 (defun muse-insert-tag (tag)
817 "Insert a tag interactively with a blank line after it."
822 (when muse-tag-history
823 (concat "(default: " (car muse-tag-history) ") ")))
825 (require 'muse-publish)
826 (mapcar 'list (nconc (mapcar 'car muse-publish-markup-tags)
828 nil nil nil 'muse-tag-history
829 (car muse-tag-history))))
831 (setq tag (car muse-tag-history)))
832 (unless (interactive-p)
833 (require 'muse-publish))
834 (let ((tag-entry (assoc tag muse-publish-markup-tags))
836 ;; Add to custom list if no entry exists
838 (add-to-list 'muse-custom-tags tag))
840 (when (nth 2 tag-entry)
841 (setq options (read-string "Option: ")))
842 (unless (equal options "")
843 (setq options (concat " " options)))
844 ;; Insert the tag, closing if necessary
845 (when tag (insert (concat "<" tag options ">")))
846 (when (nth 1 tag-entry)
847 (insert (concat "\n\n</" tag ">\n"))
852 ;;; muse-mode.el ends here