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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
52 (require 'muse-regexps
)
53 (require 'muse-project
)
55 (autoload 'muse-use-font-lock
"muse-colors")
56 (autoload 'muse-publish-this-file
"muse-publish")
57 (autoload 'muse-publish-get-style
"muse-publish")
58 (autoload 'muse-publish-output-file
"muse-publish")
63 (require 'pcomplete
) ; load if available
68 (defgroup muse-mode nil
69 "Options controlling the behavior of the Muse editing Mode."
72 (defcustom muse-mode-highlight-p t
73 "If non-nil, highlight the content of Muse buffers."
78 (defcustom muse-mode-auto-p nil
79 "If non-nil, automagically determine when Muse mode should be activated."
84 (add-hook 'find-file-hooks
'muse-mode-maybe
)
85 (remove-hook 'find-file-hooks
'muse-mode-maybe
))
89 (defun muse-mode-maybe-after-init ()
90 (when muse-mode-auto-p
91 (add-hook 'find-file-hooks
'muse-mode-maybe
)))
93 ;; If the user sets this value in their init file, make sure that
95 (add-hook 'after-init-hook
'muse-mode-maybe-after-init
)
97 (defcustom muse-mode-intangible-links nil
98 "If non-nil, use the intangible property on links.
99 This can cause problems with flyspell (and potentially fill-mode),
100 so only enable this if you don't use either of these."
104 (defcustom muse-mode-hook nil
105 "A hook that is run when Muse mode is entered."
107 :options
'(flyspell-mode footnote-mode turn-on-auto-fill
108 highlight-changes-mode
)
111 (defcustom muse-grep-command
112 "find %D -type f ! -name '*~' | xargs -I {} echo \\\"{}\\\" | xargs egrep -n -e \"%W\""
113 "The command to use when grepping for backlinks and other
114 searches through the muse projects. The string %D is replaced by
115 the directories from muse-project-alist, space-separated. The
116 string %W is replaced with the name of the muse page or whatever
117 else you are searching for. This command has been modified to
118 handle spaces in filenames, which were giving egrep a problem.
120 Note: We highly recommend using glimpse to search large projects.
121 To use glimpse, install and edit a file called .glimpse_exclude
122 in your home directory. Put a list of glob patterns in that file
123 to exclude Emacs backup files, etc. Then, run the indexer using:
125 glimpseindex -o <list of Wiki directories>
127 Once that's completed, customize this variable to have the
132 Your searches will go much, much faster, especially for very
133 large projects. Don't forget to add a user cronjob to update the
138 (defvar muse-insert-map
139 (let ((map (make-sparse-keymap)))
140 (define-key map
"l" 'muse-insert-relative-link-to-file
)
141 (define-key map
"t" 'muse-insert-tag
)
142 (define-key map
"u" 'muse-insert-url
)
146 (defvar muse-mode-map
147 (let ((map (make-sparse-keymap)))
148 (define-key map
[(control ?c
) (control ?a
)] 'muse-index
)
149 (define-key map
[(control ?c
) (control ?e
)] 'muse-edit-link-at-point
)
150 (define-key map
[(control ?c
) (control ?l
)] 'font-lock-mode
)
151 (define-key map
[(control ?c
) (control ?t
)]
152 'muse-project-publish-this-file
)
153 (define-key map
[(control ?c
) (control ?T
)] 'muse-publish-this-file
)
154 (define-key map
[(control ?c
) (control ?v
)] 'muse-browse-result
)
156 (define-key map
[(control ?c
) ?
=] 'muse-what-changed
)
158 (define-key map
[tab] 'muse-next-reference)
159 (define-key map [(control ?i)] 'muse-next-reference)
161 (if (featurep 'xemacs)
163 (define-key map [(button2)] 'muse-follow-name-at-mouse)
164 (define-key map [(shift button2)]
165 'muse-follow-name-at-mouse-other-window))
166 (define-key map [(shift control ?m)]
167 'muse-follow-name-at-point-other-window)
168 (define-key map [mouse-2] 'muse-follow-name-at-mouse)
169 (define-key map [(shift mouse-2)]
170 'muse-follow-name-at-mouse-other-window))
172 (define-key map [(shift tab)] 'muse-previous-reference)
173 (unless (featurep 'xemacs)
174 (define-key map [(shift iso-lefttab)] 'muse-previous-reference)
175 (define-key map [(shift control ?i)] 'muse-previous-reference))
177 (define-key map [(control ?c) (control ?f)] 'muse-project-find-file)
178 (define-key map [(control ?c) (control ?p)] 'muse-project-publish)
180 (define-key map [(control ?c) tab] 'muse-insert-thing)
182 ;; Searching functions
183 (define-key map [(control ?c) (control ?b)] 'muse-find-backlinks)
184 (define-key map [(control ?c) (control ?s)] 'muse-search)
186 ;; Enhanced list functions
187 (define-key map [(meta return)] 'muse-insert-list-item)
188 (define-key map [(control ?>)] 'muse-increase-list-item-indentation)
189 (define-key map [(control ?<)] 'muse-decrease-list-item-indentation)
191 (when (featurep 'pcomplete)
192 (define-key map [(meta tab)] 'pcomplete)
193 (define-key map [(meta control ?i)] 'pcomplete))
196 "Keymap used by Emacs Muse mode.")
201 (define-derived-mode muse-mode text-mode "Muse"
202 "Muse is an Emacs mode for authoring and publishing documents.
204 ;; Since we're not inheriting from normal-mode, we need to
205 ;; explicitly run file variables.
207 (hack-local-variables)
208 (error (message "File local-variables error: %s"
209 (prin1-to-string err))))
210 ;; Avoid lock-up caused by use of the 'intangible' text property
212 (unless muse-mode-intangible-links
213 (set (make-local-variable 'inhibit-point-motion-hooks) t))
214 (setq muse-current-project (muse-project-of-file))
215 (muse-project-set-variables)
216 ;; Make fill not split up links
217 (when (boundp 'fill-nobreak-predicate)
218 (make-local-variable 'fill-nobreak-predicate)
219 ;; Work around annoying inconsistency in fill handling between
221 (if (< emacs-major-version 22)
222 (setq fill-nobreak-predicate 'muse-mode-fill-nobreak-p)
223 (add-to-list 'fill-nobreak-predicate
224 'muse-mode-fill-nobreak-p)))
225 ;; Make fill work nicely with item lists
226 (set (make-local-variable 'adaptive-fill-regexp)
227 (concat "\\s-+\\(-\\|[0-9]+\\.\\)\\s-+\\|\\[[0-9]+\\]\\s-*"
228 "\\|.*\\s-*::\\s-+\\|\\s-*"))
229 (set (make-local-variable 'paragraph-start)
230 (concat paragraph-start
231 "\\|\\s-+\\(-\\|[0-9]+\\.\\)\\s-+\\|\\[[0-9]+\\]\\s-*"
232 "\\|.*\\s-*::\\s-+"))
233 ;; Comment syntax is `; comment'
234 (set (make-local-variable 'comment-start)
236 (set (make-local-variable 'comment-start-skip)
238 ;; If we're using Emacs21, this makes flyspell work like it should
239 (when (boundp 'flyspell-generic-check-word-p)
240 (set (make-local-variable 'flyspell-generic-check-word-p)
241 'muse-mode-flyspell-p))
242 ;; If pcomplete is available, set it up
243 (when (featurep 'pcomplete)
244 (set (make-local-variable 'pcomplete-default-completion-function)
245 'muse-mode-completions)
246 (set (make-local-variable 'pcomplete-command-completion-function)
247 'muse-mode-completions)
248 (set (make-local-variable 'pcomplete-parse-arguments-function)
249 'muse-mode-current-word))
250 ;; Initialize any auto-generated variables
251 (run-hooks 'muse-update-values-hook)
252 (when muse-mode-highlight-p
253 (muse-use-font-lock)))
256 'flyspell-mode-predicate
257 'muse-mode-flyspell-p)
259 (defun muse-mode-fill-nobreak-p ()
260 "Return nil if we should allow a fill to occur at point.
261 Otherwise return non-nil.
263 This is used to keep long explicit links from being mangled by
267 (and (re-search-backward "\\[\\[\\|\\]\\]"
268 (line-beginning-position) t)
269 (string= (or (match-string 0) "")
272 (defun muse-mode-flyspell-p ()
273 "Return non-nil if we should allow spell-checking to occur at point.
274 Otherwise return nil.
276 This is used to keep links from being improperly colorized by flyspell."
277 (and (not (get-text-property (if (bobp) (point) (1- (point)))
280 (null (muse-link-at-point)))))
283 (defun muse-mode-choose-mode ()
284 "Turn the proper Emacs Muse related mode on for this file."
285 (let ((project (muse-project-of-file)))
286 (funcall (or (and project (muse-get-keyword :major-mode (cadr project) t))
289 (defun muse-mode-maybe ()
290 "Maybe turn Emacs Muse mode on for this file."
291 (let ((project (muse-project-of-file)))
293 (funcall (or (muse-get-keyword :major-mode (cadr project) t)
296 ;;; Enhanced list editing
298 (defun muse-on-blank-line ()
299 "See if point is on a blank line"
302 (looking-at (concat "[" muse-regexp-blank "]?[\n]+"))))
304 (defun muse-get-paragraph-start ()
305 "Return the start of the current paragraph. This function will
306 return nil if there are no prior paragraphs and the beginning of
307 the line if point is on a blank line."
308 (let ((para-start (concat "[\n]+[" muse-regexp-blank "]?[\n]+")))
309 ;; search back to start of paragraph
312 (if (not (muse-on-blank-line))
313 (re-search-backward para-start nil t)
314 (line-beginning-position))))))
316 (defun muse-insert-thing ()
317 "Prompt for something to insert into the current buffer."
319 (message "Insert:\nl link\nt Muse tag\nu URL")
321 (let ((overriding-local-map muse-insert-map))
322 (setq key (read-key-sequence nil)))
323 (if (commandp (setq cmd (lookup-key muse-insert-map key)))
325 (call-interactively cmd))
326 (message "Not inserting anything"))))
329 (defun muse-insert-list-item ()
330 "Insert a list item at the current point, taking into account
331 your current list type and indentation level."
333 (let ((newitem " - ")
335 (pstart (muse-get-paragraph-start))
336 (list-item (format muse-list-item-regexp
337 (concat "[" muse-regexp-blank "]*"))))
338 ;; search backwards for start of current item
340 (when (re-search-backward list-item pstart t)
341 ;; save the matching item
342 (setq newitem (match-string 0))
343 ;; see what type it is
344 (if (string-match "::" (match-string 0))
345 ;; is a definition, replace the term
346 (setq newitem (concat " "
347 (read-string "Term: ")
349 ;; see if it's a numbered list
350 (when (string-match "[0-9]+" newitem)
351 ;; is numbered, so increment
354 (match-string 0 newitem))))
355 (setq newitem (replace-match
356 (number-to-string itemno)
357 nil nil newitem))))))
358 ;; insert the new item
359 (insert (concat "\n" newitem))))
361 (defun muse-alter-list-item-indentation (operation)
362 "Alter the indentation of the current list item.
363 Valid values of OPERATION are 'increase and 'decrease."
364 (let ((pstart (muse-get-paragraph-start))
365 (list-item (format muse-list-item-regexp
366 (concat "[" muse-regexp-blank "]*")))
367 beg move-func indent)
368 ;; search backwards until start of paragraph to see if we are on a
371 (if (or (progn (goto-char (muse-line-beginning-position))
373 (looking-at list-item))
374 ;; not on item, so search backwards
375 (re-search-backward list-item pstart t))
378 (setq indent (buffer-substring (match-beginning 0)
379 (match-beginning 1)))
380 (muse-forward-list-item (muse-list-item-type (match-string 1))
381 (concat "[" muse-regexp-blank "]*")
384 (narrow-to-region beg (point))
385 (goto-char (point-min))
387 (while (< (point) (point-max))
388 ;; increase or decrease the indentation
390 (cond ((eq operation 'increase)
392 ((eq operation 'decrease)
394 ;; we have enough space, so delete it
395 (delete-region (match-beginning 0)
399 ;; we are not on an item, so warn
400 (message "You are not on a list item.")))))
403 (defun muse-increase-list-item-indentation ()
404 "Increase the indentation of the current list item."
406 (muse-alter-list-item-indentation 'increase))
409 (defun muse-decrease-list-item-indentation ()
410 "Decrease the indentation of the current list item."
412 (muse-alter-list-item-indentation 'decrease))
414 ;;; Support page name completion using pcomplete
416 (defun muse-mode-completions ()
417 "Return a list of possible completions names for this buffer."
418 (let ((project (muse-project-of-file)))
420 (while (pcomplete-here
421 (mapcar 'car (muse-project-file-alist project)))))))
423 (defun muse-mode-current-word ()
427 (skip-chars-backward (concat "^\\[\n" muse-regexp-blank))
428 (narrow-to-region (point) end))
429 (pcomplete-parse-buffer-arguments))))
431 ;;; Navigate/visit links or URLs. Use TAB, S-TAB and RET (or mouse-2).
433 (defun muse-link-at-point (&optional pos)
434 "Return link text if a URL or link is at point."
435 (let ((case-fold-search nil)
436 (inhibit-point-motion-hooks t)
437 (here (or pos (point))))
438 ;; if we are using muse-colors, we can just use link properties to
439 ;; determine whether we are on a link
440 (if (featurep 'muse-colors)
441 (when (get-text-property here 'muse-link)
443 (when (and (not (bobp))
444 (get-text-property (1- here) 'muse-link))
445 (goto-char (or (previous-single-property-change here 'muse-link)
447 (if (looking-at muse-explicit-link-regexp)
449 (goto-char (match-beginning 1))
450 (muse-handle-explicit-link))
451 (muse-handle-implicit-link))))
452 ;; use fallback method to find a link
454 (and (char-after pos)
455 (not (eq (char-syntax (char-after pos)) ?\ ))))
458 ;; check for explicit link here or before point
459 (if (or (looking-at muse-explicit-link-regexp)
461 (re-search-backward "\\[\\[\\|\\]\\]"
462 (muse-line-beginning-position)
464 (string= (or (match-string 0) "") "[[")
465 (looking-at muse-explicit-link-regexp)))
467 (goto-char (match-beginning 1))
468 (muse-handle-explicit-link))
470 ;; check for bare URL or other link type
471 (skip-chars-backward (concat "^'\"<>{}(\n" muse-regexp-blank))
472 (and (looking-at muse-implicit-link-regexp)
473 (muse-handle-implicit-link))))))))
475 (defun muse-make-link (link &optional desc)
476 "Return a link to LINK with DESC as the description."
477 (when (string-match muse-explicit-link-regexp link)
478 (unless desc (setq desc (muse-get-link-desc link)))
479 (setq link (muse-get-link link)))
482 (not (string= desc ""))
483 (not (string= link desc)))
484 (concat "[[" (muse-link-escape link) "][" (muse-link-escape desc) "]]")
485 (concat "[[" (or (muse-link-escape link) "") "]]")))
488 (defun muse-insert-relative-link-to-file ()
489 "Insert a relative link to a file, with optional description, at point."
490 ;; Perhaps the relative location should be configurable, so that the
491 ;; file search would start in the publishing directory and then
492 ;; insert the link relative to the publishing directory
495 (muse-make-link (file-relative-name (read-file-name "Link: "))
496 (read-string "Text: "))))
498 (defun muse-insert-url ()
499 "Insert a URL, with optional description, at point."
502 (muse-make-link (read-string "URL: ")
503 (read-string "Text: "))))
506 (defun muse-edit-link-at-point ()
507 "Edit the current link.
508 Do not rename the page originally referred to."
510 (if (muse-link-at-point)
511 (let ((link (muse-link-unescape (muse-get-link)))
512 (desc (muse-link-unescape (muse-get-link-desc))))
516 (read-string "Link: " link)
517 (read-string "Text: " desc)))
519 (error "There is no valid link at point")))
521 (defun muse-visit-link-default (link &optional other-window)
522 "Visit the URL or link named by LINK.
523 If ANCHOR is specified, search for it after opening LINK.
525 This is the default function to call when visiting links; it is
526 used by `muse-visit-link' if you have not specified :visit-link
527 in `muse-project-alist'."
528 (if (string-match muse-url-regexp link)
529 (muse-browse-url link)
532 (when (string-match "#" link)
533 (setq anchor (substring link (match-beginning 0))
534 link (if (= (match-beginning 0) 0)
535 ;; If there is an anchor but no link, default
536 ;; to the current page.
538 (substring link 0 (match-beginning 0)))))
540 (setq base-buffer (get-buffer link))
541 (if (and base-buffer (not (buffer-file-name base-buffer)))
542 ;; If file is temporary (no associated file), just switch to
545 (switch-to-buffer-other-window base-buffer)
546 (switch-to-buffer base-buffer))
547 (let ((project (muse-project-of-file)))
549 (muse-project-find-file link project
551 'find-file-other-window))
553 (find-file-other-window link)
554 (find-file link))))))
557 (goto-char (point-min))
558 (unless (re-search-forward (concat "^\\W*" (regexp-quote anchor)
561 (goto-char pos)))))))
563 (defun muse-visit-link (link &optional other-window)
564 "Visit the URL or link named by LINK."
565 (let ((visit-link-function
566 (muse-get-keyword :visit-link (cadr (muse-project-of-file)) t)))
567 (if visit-link-function
568 (funcall visit-link-function link other-window)
569 (muse-visit-link-default link other-window))))
572 (defun muse-browse-result (style &optional other-window)
573 "Visit the current page's published result."
575 (list (muse-project-get-applicable-style buffer-file-name
576 (cddr muse-current-project))
578 (setq style (muse-style style))
580 (muse-publish-output-file buffer-file-name
581 (muse-style-element :path style) style)))
582 (if (not (file-readable-p result-path))
583 (error "Cannot open output file '%s'" result-path)
585 (find-file-other-window result-path)
586 (let ((func (muse-style-element :browser style t)))
588 (funcall func result-path)
589 (message "The %s publishing style does not support browsing."
593 (defun muse-follow-name-at-point (&optional other-window)
594 "Visit the link at point."
596 (let ((link (muse-link-at-point)))
598 (muse-visit-link link other-window)
599 (error "There is no valid link at point"))))
602 (defun muse-follow-name-at-point-other-window ()
603 "Visit the link at point in other window."
605 (muse-follow-name-at-point t))
607 (defun muse-follow-name-at-mouse (event &optional other-window)
608 "Visit the link at point, or yank text if none is found."
612 (cond ((fboundp 'event-window) ; XEmacs
613 (set-buffer (window-buffer (event-window event)))
614 (and (funcall (symbol-function 'event-point) event)
615 (goto-char (funcall (symbol-function 'event-point)
617 ((fboundp 'posn-window) ; Emacs
618 (set-buffer (window-buffer (posn-window (event-start event))))
619 (goto-char (posn-point (event-start event)))))
620 (let ((link (muse-link-at-point)))
622 (muse-visit-link link other-window)
624 ;; Fall back to normal binding for this event
626 (lookup-key (current-global-map) (this-command-keys)))))
628 (defun muse-follow-name-at-mouse-other-window (event)
629 "Visit the link at point"
631 ;; throw away the old window position, since other-window will
633 (select-window (car (cadr event)))
634 (muse-follow-name-at-mouse event t))
637 (defun muse-next-reference ()
638 "Move forward to next Muse link or URL, cycling if necessary."
642 (when (get-text-property (point) 'muse-link)
643 (goto-char (or (next-single-property-change (point) 'muse-link)
646 (setq pos (next-single-property-change (point) 'muse-link))
649 (if (get-text-property (point-min) 'muse-link)
650 (setq pos (point-min))
651 (setq pos (next-single-property-change (point-min) 'muse-link)))))
657 (defun muse-previous-reference ()
658 "Move backward to the next Muse link or URL, cycling if necessary.
659 In case of Emacs x <= 21 and ignoring of intangible properties (see
660 `muse-mode-intangible-links').
662 This function is not entirely accurate, but it's close enough."
667 ;; Hack: The user perceives the two cases of point ("|")
668 ;; position (1) "|[[" and (2) "[[|" or "][|" as "point is at
669 ;; start of link". But in the sense of the function
670 ;; "previous-single-property-change" these two cases are
671 ;; different. The following code aligns these two cases. Emacs
672 ;; 21: If the intangible property is ignored case (2) is more
673 ;; complicate and this hack only solves the problem partially.
675 (when (and (get-text-property (point) 'muse-link)
676 (muse-looking-back "\\[\\|\\]"))
677 (goto-char (or (previous-single-property-change (point) 'muse-link)
680 (when (eq (point) (point-min))
681 (goto-char (point-max)))
683 (setq pos (previous-single-property-change (point) 'muse-link))
686 (if (get-text-property (point-min) 'muse-link)
687 (setq pos (point-min))
688 (setq pos (previous-single-property-change (point-max)
692 (if (get-text-property pos 'muse-link)
694 (goto-char (or (previous-single-property-change pos 'muse-link)
698 (defun muse-what-changed ()
699 "Show the unsaved changes that have been made to the current file."
701 (diff-backup buffer-file-name))
704 ;;; Find text in project pages, or pages referring to the current page
706 (defvar muse-search-history nil)
708 (defun muse-grep (string &optional grep-command-no-shadow)
709 "Grep for STRING in the project directories.
710 GREP-COMMAND if passed will supplant `muse-grep-command'."
711 ;; careful - grep-command leaks into compile, so we call it
712 ;; -no-shadow instead
714 (let* ((str (or grep-command-no-shadow muse-grep-command))
715 (muse-directories (mapcar
719 (dirs (mapconcat (lambda (dir)
720 (shell-quote-argument
721 (expand-file-name dir)))
722 muse-directories " ")))
723 (while (string-match "%W" str)
724 (setq str (replace-match string t t str)))
725 (while (string-match "%D" str)
726 (setq str (replace-match dirs t t str)))
727 (if (fboundp 'compilation-start)
728 (compilation-start str nil (lambda (&rest args) "*search*")
730 (and (fboundp 'compile-internal)
731 (compile-internal str "No more search hits" "search"
732 nil grep-regexp-alist)))))
735 (defun muse-search-with-command (text)
736 "Search for the given TEXT string in the project directories
737 using the specified command."
739 (list (let ((str (concat muse-grep-command)) pos)
740 (when (string-match "%W" str)
741 (setq pos (match-beginning 0))
742 (unless (featurep 'xemacs)
744 (setq str (replace-match "" t t str)))
745 (read-from-minibuffer "Search command: "
746 (cons str pos) nil nil
747 'muse-search-history))))
748 (muse-grep nil text))
751 (defun muse-search ()
752 "Search for the given TEXT using the default grep command."
754 (muse-grep (read-string "Search: ")))
757 (defun muse-find-backlinks ()
758 "Grep for the current pagename in all the project directories."
760 (muse-grep (muse-page-name)))
763 ;;; Generate an index of all known Muse pages
765 (defun muse-generate-index (&optional as-list exclude-private)
766 "Generate an index of all Muse pages."
767 (let ((index (muse-index-as-string as-list exclude-private)))
768 (with-current-buffer (get-buffer-create "*Muse Index*")
775 "Display an index of all known Muse pages."
777 (message "Generating Muse index...")
778 (let ((project (muse-project)))
779 (with-current-buffer (muse-generate-index)
780 (goto-char (point-min))
782 (setq muse-current-project project)
783 (pop-to-buffer (current-buffer))))
784 (message "Generating Muse index...done"))
786 (defun muse-index-as-string (&optional as-list exclude-private exclude-current)
787 "Generate an index of all Muse pages.
788 If AS-LIST is non-nil, insert a dash and spaces before each item.
789 If EXCLUDE-PRIVATE is non-nil, exclude files that have private permissions.
790 If EXCLUDE-CURRENT is non-nil, exclude the current file from the output."
791 (let ((files (sort (copy-alist (muse-project-file-alist))
794 (string-lessp (car l) (car r)))))))
795 (when (and exclude-current (muse-page-name))
796 (setq files (delete (assoc (muse-page-name) files) files)))
799 (unless (and exclude-private
800 (muse-project-private-p (cdar files)))
801 (insert (if as-list " - " "") "[[" (caar files) "]]\n"))
802 (setq files (cdr files)))
805 ;;; Insert tags interactively on C-c TAB t
807 (defvar muse-tag-history nil
808 "List of recently-entered tags; used by `muse-insert-tag'.
809 If you want a tag to start as the default, you may manually set
810 this variable to a list.")
812 (defvar muse-custom-tags nil
813 "Keep track of any new tags entered in `muse-insert-tag'.
814 If there are (X)HTML tags that you use frequently with that
815 function, you might want to set this manually.")
818 (defun muse-insert-tag (tag)
819 "Insert a tag interactively with a blank line after it."
824 (when muse-tag-history
825 (concat "(default: " (car muse-tag-history) ") ")))
827 (require 'muse-publish)
828 (mapcar 'list (nconc (mapcar 'car muse-publish-markup-tags)
830 nil nil nil 'muse-tag-history
831 (car muse-tag-history))))
833 (setq tag (car muse-tag-history)))
834 (unless (interactive-p)
835 (require 'muse-publish))
836 (let ((tag-entry (assoc tag muse-publish-markup-tags))
838 ;; Add to custom list if no entry exists
840 (add-to-list 'muse-custom-tags tag))
842 (when (nth 2 tag-entry)
843 (setq options (read-string "Option: ")))
844 (unless (equal options "")
845 (setq options (concat " " options)))
846 ;; Insert the tag, closing if necessary
847 (when tag (insert (concat "<" tag options ">")))
848 (when (nth 1 tag-entry)
849 (insert (concat "\n\n</" tag ">\n"))
852 ;;; muse-mode.el ends here