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 ?c
)] 'muse-follow-name-at-point
)
148 (define-key map
[(control ?c
) (control ?e
)] 'muse-edit-link-at-point
)
149 (define-key map
[(control ?c
) (control ?l
)] 'font-lock-mode
)
150 (define-key map
[(control ?c
) (control ?t
)]
151 'muse-project-publish-this-file
)
152 (define-key map
[(control ?c
) (control ?T
)] 'muse-publish-this-file
)
153 (define-key map
[(control ?c
) (control ?v
)] 'muse-browse-result
)
155 (define-key map
[(control ?c
) ?
=] 'muse-what-changed
)
157 (define-key map
[tab] 'muse-next-reference)
158 (define-key map [(control ?i)] 'muse-next-reference)
160 (if (featurep 'xemacs)
162 (define-key map [(button2)] 'muse-follow-name-at-mouse)
163 (define-key map [(shift button2)]
164 'muse-follow-name-at-mouse-other-window))
165 (define-key map [(shift control ?m)]
166 'muse-follow-name-at-point-other-window)
167 (define-key map [mouse-2] 'muse-follow-name-at-mouse)
168 (define-key map [(shift mouse-2)]
169 'muse-follow-name-at-mouse-other-window))
171 (define-key map [(shift tab)] 'muse-previous-reference)
172 (unless (featurep 'xemacs)
173 (define-key map [(shift iso-lefttab)] 'muse-previous-reference)
174 (define-key map [(shift control ?i)] 'muse-previous-reference))
176 (define-key map [(control ?c) (control ?f)] 'muse-project-find-file)
177 (define-key map [(control ?c) (control ?p)] 'muse-project-publish)
179 (define-key map [(control ?c) tab] 'muse-insert-thing)
181 ;; Searching functions
182 (define-key map [(control ?c) (control ?b)] 'muse-find-backlinks)
183 (define-key map [(control ?c) (control ?s)] 'muse-search)
185 ;; Enhanced list functions
186 (define-key map [(meta return)] 'muse-insert-list-item)
187 (define-key map [(control ?>)] 'muse-increase-list-item-indentation)
188 (define-key map [(control ?<)] 'muse-decrease-list-item-indentation)
190 (when (featurep 'pcomplete)
191 (define-key map [(meta tab)] 'pcomplete)
192 (define-key map [(meta control ?i)] 'pcomplete))
195 "Keymap used by Emacs Muse mode.")
200 (define-derived-mode muse-mode text-mode "Muse"
201 "Muse is an Emacs mode for authoring and publishing documents.
203 ;; Since we're not inheriting from normal-mode, we need to
204 ;; explicitly run file variables.
206 (hack-local-variables)
207 (error (message "File local-variables error: %s"
208 (prin1-to-string err))))
209 ;; Avoid lock-up caused by use of the 'intangible' text property
211 (unless muse-mode-intangible-links
212 (set (make-local-variable 'inhibit-point-motion-hooks) t))
213 (setq muse-current-project (muse-project-of-file))
214 (muse-project-set-variables)
215 ;; Make fill not split up links
216 (when (boundp 'fill-nobreak-predicate)
217 (make-local-variable 'fill-nobreak-predicate)
218 ;; Work around annoying inconsistency in fill handling between
220 (if (< emacs-major-version 22)
221 (setq fill-nobreak-predicate 'muse-mode-fill-nobreak-p)
222 (add-to-list 'fill-nobreak-predicate
223 'muse-mode-fill-nobreak-p)))
224 ;; Make fill work nicely with item lists
225 (set (make-local-variable 'adaptive-fill-regexp)
226 (concat "\\s-+\\(-\\|[0-9]+\\.\\)\\s-+\\|\\[[0-9]+\\]\\s-*"
227 "\\|.*\\s-*::\\s-+\\|\\s-*"))
228 (set (make-local-variable 'paragraph-start)
229 (concat paragraph-start
230 "\\|\\s-+\\(-\\|[0-9]+\\.\\)\\s-+\\|\\[[0-9]+\\]\\s-*"
231 "\\|.*\\s-*::\\s-+"))
232 ;; Comment syntax is `; comment'
233 (set (make-local-variable 'comment-start)
235 (set (make-local-variable 'comment-start-skip)
237 ;; If we're using Emacs21, this makes flyspell work like it should
238 (when (boundp 'flyspell-generic-check-word-p)
239 (set (make-local-variable 'flyspell-generic-check-word-p)
240 'muse-mode-flyspell-p))
241 ;; If pcomplete is available, set it up
242 (when (featurep 'pcomplete)
243 (set (make-local-variable 'pcomplete-default-completion-function)
244 'muse-mode-completions)
245 (set (make-local-variable 'pcomplete-command-completion-function)
246 'muse-mode-completions)
247 (set (make-local-variable 'pcomplete-parse-arguments-function)
248 'muse-mode-current-word))
249 ;; Initialize any auto-generated variables
250 (run-hooks 'muse-update-values-hook)
251 (when muse-mode-highlight-p
252 (muse-use-font-lock)))
255 'flyspell-mode-predicate
256 'muse-mode-flyspell-p)
258 (defun muse-mode-fill-nobreak-p ()
259 "Return nil if we should allow a fill to occur at point.
260 Otherwise return non-nil.
262 This is used to keep long explicit links from being mangled by
266 (and (re-search-backward "\\[\\[\\|\\]\\]"
267 (line-beginning-position) t)
268 (string= (or (match-string 0) "")
271 (defun muse-mode-flyspell-p ()
272 "Return non-nil if we should allow spell-checking to occur at point.
273 Otherwise return nil.
275 This is used to keep links from being improperly colorized by flyspell."
276 (and (not (get-text-property (if (bobp) (point) (1- (point)))
279 (null (muse-link-at-point)))))
282 (defun muse-mode-choose-mode ()
283 "Turn the proper Emacs Muse related mode on for this file."
284 (let ((project (muse-project-of-file)))
285 (funcall (or (and project (muse-get-keyword :major-mode (cadr project) t))
288 (defun muse-mode-maybe ()
289 "Maybe turn Emacs Muse mode on for this file."
290 (let ((project (muse-project-of-file)))
292 (funcall (or (muse-get-keyword :major-mode (cadr project) t)
295 ;;; Enhanced list editing
297 (defun muse-on-blank-line ()
298 "See if point is on a blank line"
301 (looking-at (concat "[" muse-regexp-blank "]?[\n]+"))))
303 (defun muse-get-paragraph-start ()
304 "Return the start of the current paragraph. This function will
305 return nil if there are no prior paragraphs and the beginning of
306 the line if point is on a blank line."
307 (let ((para-start (concat "[\n]+[" muse-regexp-blank "]?[\n]+")))
308 ;; search back to start of paragraph
311 (if (not (muse-on-blank-line))
312 (re-search-backward para-start nil t)
313 (line-beginning-position))))))
315 (defun muse-insert-thing ()
316 "Prompt for something to insert into the current buffer."
318 (message "Insert:\nl link\nt Muse tag\nu URL")
320 (let ((overriding-local-map muse-insert-map))
321 (setq key (read-key-sequence nil)))
322 (if (commandp (setq cmd (lookup-key muse-insert-map key)))
324 (call-interactively cmd))
325 (message "Not inserting anything"))))
328 (defun muse-insert-list-item ()
329 "Insert a list item at the current point, taking into account
330 your current list type and indentation level."
332 (let ((newitem " - ")
334 (pstart (muse-get-paragraph-start))
335 (list-item (format muse-list-item-regexp
336 (concat "[" muse-regexp-blank "]*"))))
337 ;; search backwards for start of current item
339 (when (re-search-backward list-item pstart t)
340 ;; save the matching item
341 (setq newitem (match-string 0))
342 ;; see what type it is
343 (if (string-match "::" (match-string 0))
344 ;; is a definition, replace the term
345 (setq newitem (concat " "
346 (read-string "Term: ")
348 ;; see if it's a numbered list
349 (when (string-match "[0-9]+" newitem)
350 ;; is numbered, so increment
353 (match-string 0 newitem))))
354 (setq newitem (replace-match
355 (number-to-string itemno)
356 nil nil newitem))))))
357 ;; insert the new item
358 (insert (concat "\n" newitem))))
360 (defun muse-alter-list-item-indentation (operation)
361 "Alter the indentation of the current list item.
362 Valid values of OPERATION are 'increase and 'decrease."
363 (let ((pstart (muse-get-paragraph-start))
364 (list-item (format muse-list-item-regexp
365 (concat "[" muse-regexp-blank "]*")))
366 beg move-func indent)
367 ;; search backwards until start of paragraph to see if we are on a
370 (if (or (progn (goto-char (muse-line-beginning-position))
372 (looking-at list-item))
373 ;; not on item, so search backwards
374 (re-search-backward list-item pstart t))
377 (setq indent (buffer-substring (match-beginning 0)
378 (match-beginning 1)))
379 (muse-forward-list-item (muse-list-item-type (match-string 1))
380 (concat "[" muse-regexp-blank "]*")
383 (narrow-to-region beg (point))
384 (goto-char (point-min))
386 (while (< (point) (point-max))
387 ;; increase or decrease the indentation
389 (cond ((eq operation 'increase)
391 ((eq operation 'decrease)
393 ;; we have enough space, so delete it
394 (delete-region (match-beginning 0)
398 ;; we are not on an item, so warn
399 (message "You are not on a list item.")))))
402 (defun muse-increase-list-item-indentation ()
403 "Increase the indentation of the current list item."
405 (muse-alter-list-item-indentation 'increase))
408 (defun muse-decrease-list-item-indentation ()
409 "Decrease the indentation of the current list item."
411 (muse-alter-list-item-indentation 'decrease))
413 ;;; Support page name completion using pcomplete
415 (defun muse-mode-completions ()
416 "Return a list of possible completions names for this buffer."
417 (let ((project (muse-project-of-file)))
419 (while (pcomplete-here
420 (mapcar 'car (muse-project-file-alist project)))))))
422 (defun muse-mode-current-word ()
426 (skip-chars-backward (concat "^\\[\n" muse-regexp-blank))
427 (narrow-to-region (point) end))
428 (pcomplete-parse-buffer-arguments))))
430 ;;; Navigate/visit links or URLs. Use TAB, S-TAB and RET (or mouse-2).
432 (defun muse-link-at-point (&optional pos)
433 "Return link text if a URL or link is at point."
434 (let ((case-fold-search nil)
435 (inhibit-point-motion-hooks t)
436 (here (or pos (point))))
437 ;; if we are using muse-colors, we can just use link properties to
438 ;; determine whether we are on a link
439 (if (featurep 'muse-colors)
440 (when (get-text-property here 'muse-link)
442 (when (and (not (bobp))
443 (get-text-property (1- here) 'muse-link))
444 (goto-char (or (previous-single-property-change here 'muse-link)
446 (if (looking-at muse-explicit-link-regexp)
448 (goto-char (match-beginning 1))
449 (muse-handle-explicit-link))
450 (muse-handle-implicit-link))))
451 ;; use fallback method to find a link
453 (and (char-after pos)
454 (not (eq (char-syntax (char-after pos)) ?\ ))))
457 ;; check for explicit link here or before point
458 (if (or (looking-at muse-explicit-link-regexp)
460 (re-search-backward "\\[\\[\\|\\]\\]"
461 (muse-line-beginning-position)
463 (string= (or (match-string 0) "") "[[")
464 (looking-at muse-explicit-link-regexp)))
466 (goto-char (match-beginning 1))
467 (muse-handle-explicit-link))
469 ;; check for bare URL or other link type
470 (skip-chars-backward (concat "^'\"<>{}(\n" muse-regexp-blank))
471 (and (looking-at muse-implicit-link-regexp)
472 (muse-handle-implicit-link))))))))
474 (defun muse-make-link (link &optional desc)
475 "Return a link to LINK with DESC as the description."
476 (when (string-match muse-explicit-link-regexp link)
477 (unless desc (setq desc (muse-get-link-desc link)))
478 (setq link (muse-get-link link)))
481 (not (string= desc ""))
482 (not (string= link desc)))
483 (concat "[[" (muse-link-escape link) "][" (muse-link-escape desc) "]]")
484 (concat "[[" (or (muse-link-escape link) "") "]]")))
487 (defun muse-insert-relative-link-to-file ()
488 "Insert a relative link to a file, with optional description, at point."
489 ;; Perhaps the relative location should be configurable, so that the
490 ;; file search would start in the publishing directory and then
491 ;; insert the link relative to the publishing directory
494 (muse-make-link (file-relative-name (read-file-name "Link: "))
495 (read-string "Text: "))))
497 (defun muse-insert-url ()
498 "Insert a URL, with optional description, at point."
501 (muse-make-link (read-string "URL: ")
502 (read-string "Text: "))))
505 (defun muse-edit-link-at-point ()
506 "Edit the current link.
507 Do not rename the page originally referred to."
509 (if (muse-link-at-point)
510 (let ((link (muse-link-unescape (muse-get-link)))
511 (desc (muse-link-unescape (muse-get-link-desc))))
515 (read-string "Link: " link)
516 (read-string "Text: " desc)))
518 (error "There is no valid link at point")))
520 (defun muse-visit-link-default (link &optional other-window)
521 "Visit the URL or link named by LINK.
522 If ANCHOR is specified, search for it after opening LINK.
524 This is the default function to call when visiting links; it is
525 used by `muse-visit-link' if you have not specified :visit-link
526 in `muse-project-alist'."
527 (if (string-match muse-url-regexp link)
528 (muse-browse-url link)
531 (when (string-match "#" link)
532 (setq anchor (substring link (match-beginning 0))
533 link (if (= (match-beginning 0) 0)
534 ;; If there is an anchor but no link, default
535 ;; to the current page.
537 (substring link 0 (match-beginning 0)))))
539 (setq base-buffer (get-buffer link))
540 (if (and base-buffer (not (buffer-file-name base-buffer)))
541 ;; If file is temporary (no associated file), just switch to
544 (switch-to-buffer-other-window base-buffer)
545 (switch-to-buffer base-buffer))
546 (let ((project (muse-project-of-file)))
548 (muse-project-find-file link project
550 'find-file-other-window))
552 (find-file-other-window link)
553 (find-file link))))))
556 (goto-char (point-min))
557 (unless (re-search-forward (concat "^\\W*" (regexp-quote anchor)
560 (goto-char pos)))))))
562 (defun muse-visit-link (link &optional other-window)
563 "Visit the URL or link named by LINK."
564 (let ((visit-link-function
565 (muse-get-keyword :visit-link (cadr (muse-project-of-file)) t)))
566 (if visit-link-function
567 (funcall visit-link-function link other-window)
568 (muse-visit-link-default link other-window))))
571 (defun muse-browse-result (style &optional other-window)
572 "Visit the current page's published result."
574 (list (muse-project-get-applicable-style buffer-file-name
575 (cddr muse-current-project))
577 (setq style (muse-style style))
579 (muse-publish-output-file buffer-file-name
580 (muse-style-element :path style) style)))
581 (if (not (file-readable-p result-path))
582 (error "Cannot open output file '%s'" result-path)
584 (find-file-other-window result-path)
585 (let ((func (muse-style-element :browser style t)))
587 (funcall func result-path)
588 (message "The %s publishing style does not support browsing."
592 (defun muse-follow-name-at-point (&optional other-window)
593 "Visit the link at point."
595 (let ((link (muse-link-at-point)))
597 (muse-visit-link link other-window)
598 (error "There is no valid link at point"))))
601 (defun muse-follow-name-at-point-other-window ()
602 "Visit the link at point in other window."
604 (muse-follow-name-at-point t))
606 (defun muse-follow-name-at-mouse (event &optional other-window)
607 "Visit the link at point, or yank text if none is found."
611 (cond ((fboundp 'event-window) ; XEmacs
612 (set-buffer (window-buffer (event-window event)))
613 (and (funcall (symbol-function 'event-point) event)
614 (goto-char (funcall (symbol-function 'event-point)
616 ((fboundp 'posn-window) ; Emacs
617 (set-buffer (window-buffer (posn-window (event-start event))))
618 (goto-char (posn-point (event-start event)))))
619 (let ((link (muse-link-at-point)))
621 (muse-visit-link link other-window)
623 ;; Fall back to normal binding for this event
625 (lookup-key (current-global-map) (this-command-keys)))))
627 (defun muse-follow-name-at-mouse-other-window (event)
628 "Visit the link at point"
630 ;; throw away the old window position, since other-window will
632 (select-window (car (cadr event)))
633 (muse-follow-name-at-mouse event t))
636 (defun muse-next-reference ()
637 "Move forward to next Muse link or URL, cycling if necessary."
641 (when (get-text-property (point) 'muse-link)
642 (goto-char (or (next-single-property-change (point) 'muse-link)
645 (setq pos (next-single-property-change (point) 'muse-link))
648 (if (get-text-property (point-min) 'muse-link)
649 (setq pos (point-min))
650 (setq pos (next-single-property-change (point-min) 'muse-link)))))
656 (defun muse-previous-reference ()
657 "Move backward to the next Muse link or URL, cycling if necessary.
658 In case of Emacs x <= 21 and ignoring of intangible properties (see
659 `muse-mode-intangible-links').
661 This function is not entirely accurate, but it's close enough."
666 ;; Hack: The user perceives the two cases of point ("|")
667 ;; position (1) "|[[" and (2) "[[|" or "][|" as "point is at
668 ;; start of link". But in the sense of the function
669 ;; "previous-single-property-change" these two cases are
670 ;; different. The following code aligns these two cases. Emacs
671 ;; 21: If the intangible property is ignored case (2) is more
672 ;; complicate and this hack only solves the problem partially.
674 (when (and (get-text-property (point) 'muse-link)
675 (muse-looking-back "\\[\\|\\]"))
676 (goto-char (or (previous-single-property-change (point) 'muse-link)
679 (when (eq (point) (point-min))
680 (goto-char (point-max)))
682 (setq pos (previous-single-property-change (point) 'muse-link))
685 (if (get-text-property (point-min) 'muse-link)
686 (setq pos (point-min))
687 (setq pos (previous-single-property-change (point-max)
691 (if (get-text-property pos 'muse-link)
693 (goto-char (or (previous-single-property-change pos 'muse-link)
697 (defun muse-what-changed ()
698 "Show the unsaved changes that have been made to the current file."
700 (diff-backup buffer-file-name))
703 ;;; Find text in project pages, or pages referring to the current page
705 (defvar muse-search-history nil)
707 (defun muse-grep (string &optional grep-command-no-shadow)
708 "Grep for STRING in the project directories.
709 GREP-COMMAND if passed will supplant `muse-grep-command'."
710 ;; careful - grep-command leaks into compile, so we call it
711 ;; -no-shadow instead
713 (let* ((str (or grep-command-no-shadow muse-grep-command))
714 (muse-directories (mapcar
718 (dirs (mapconcat (lambda (dir)
719 (shell-quote-argument
720 (expand-file-name dir)))
721 muse-directories " ")))
722 (while (string-match "%W" str)
723 (setq str (replace-match string t t str)))
724 (while (string-match "%D" str)
725 (setq str (replace-match dirs t t str)))
726 (if (fboundp 'compilation-start)
727 (compilation-start str nil (lambda (&rest args) "*search*")
729 (and (fboundp 'compile-internal)
730 (compile-internal str "No more search hits" "search"
731 nil grep-regexp-alist)))))
734 (defun muse-search-with-command (text)
735 "Search for the given TEXT string in the project directories
736 using the specified command."
738 (list (let ((str (concat muse-grep-command)) pos)
739 (when (string-match "%W" str)
740 (setq pos (match-beginning 0))
741 (unless (featurep 'xemacs)
743 (setq str (replace-match "" t t str)))
744 (read-from-minibuffer "Search command: "
745 (cons str pos) nil nil
746 'muse-search-history))))
747 (muse-grep nil text))
750 (defun muse-search ()
751 "Search for the given TEXT using the default grep command."
753 (muse-grep (read-string "Search: ")))
756 (defun muse-find-backlinks ()
757 "Grep for the current pagename in all the project directories."
759 (muse-grep (muse-page-name)))
762 ;;; Generate an index of all known Muse pages
764 (defun muse-generate-index (&optional as-list exclude-private)
765 "Generate an index of all Muse pages."
766 (let ((index (muse-index-as-string as-list exclude-private)))
767 (with-current-buffer (get-buffer-create "*Muse Index*")
774 "Display an index of all known Muse pages."
776 (message "Generating Muse index...")
777 (let ((project (muse-project)))
778 (with-current-buffer (muse-generate-index)
779 (goto-char (point-min))
781 (setq muse-current-project project)
782 (pop-to-buffer (current-buffer))))
783 (message "Generating Muse index...done"))
785 (defun muse-index-as-string (&optional as-list exclude-private exclude-current)
786 "Generate an index of all Muse pages.
787 If AS-LIST is non-nil, insert a dash and spaces before each item.
788 If EXCLUDE-PRIVATE is non-nil, exclude files that have private permissions.
789 If EXCLUDE-CURRENT is non-nil, exclude the current file from the output."
790 (let ((files (sort (copy-alist (muse-project-file-alist))
793 (string-lessp (car l) (car r)))))))
794 (when (and exclude-current (muse-page-name))
795 (setq files (delete (assoc (muse-page-name) files) files)))
798 (unless (and exclude-private
799 (muse-project-private-p (cdar files)))
800 (insert (if as-list " - " "") "[[" (caar files) "]]\n"))
801 (setq files (cdr files)))
804 ;;; Insert tags interactively on C-c TAB t
806 (defvar muse-tag-history nil
807 "List of recently-entered tags; used by `muse-insert-tag'.
808 If you want a tag to start as the default, you may manually set
809 this variable to a list.")
811 (defvar muse-custom-tags nil
812 "Keep track of any new tags entered in `muse-insert-tag'.
813 If there are (X)HTML tags that you use frequently with that
814 function, you might want to set this manually.")
817 (defun muse-insert-tag (tag)
818 "Insert a tag interactively with a blank line after it."
823 (when muse-tag-history
824 (concat "(default: " (car muse-tag-history) ") ")))
826 (require 'muse-publish)
827 (mapcar 'list (nconc (mapcar 'car muse-publish-markup-tags)
829 nil nil nil 'muse-tag-history
830 (car muse-tag-history))))
832 (setq tag (car muse-tag-history)))
833 (unless (interactive-p)
834 (require 'muse-publish))
835 (let ((tag-entry (assoc tag muse-publish-markup-tags))
837 ;; Add to custom list if no entry exists
839 (add-to-list 'muse-custom-tags tag))
841 (when (nth 2 tag-entry)
842 (setq options (read-string "Option: ")))
843 (unless (equal options "")
844 (setq options (concat " " options)))
845 ;; Insert the tag, closing if necessary
846 (when tag (insert (concat "<" tag options ">")))
847 (when (nth 1 tag-entry)
848 (insert (concat "\n\n</" tag ">\n"))
853 ;;; muse-mode.el ends here