225
225
(add-to-list 'fill-nobreak-predicate
226
226
'muse-mode-fill-nobreak-p)))
227
227
;; Make fill work nicely with item lists
228
(set (make-local-variable 'adaptive-fill-regexp)
229
(concat "\\s-+\\(-\\|[0-9]+\\.\\)\\s-+\\|\\[[0-9]+\\]\\s-*"
230
"\\|.*\\s-*::\\s-+\\|\\s-*"))
231
(set (make-local-variable 'paragraph-start)
232
(concat paragraph-start
233
"\\|\\s-+\\(-\\|[0-9]+\\.\\)\\s-+\\|\\[[0-9]+\\]\\s-*"
234
"\\|.*\\s-*::\\s-+"))
228
(let ((regexp (concat "\\s-+\\(-\\|[0-9]+\\.\\)\\s-+"
229
"\\|\\[[0-9]+\\]\\s-*"
230
"\\|.*\\s-*::\\s-+")))
231
(set (make-local-variable 'adaptive-fill-regexp)
232
(concat regexp "\\|\\s-*"))
233
(set (make-local-variable 'paragraph-start)
234
(concat paragraph-start "\\|" regexp)))
235
235
;; Comment syntax is `; comment'
236
236
(set (make-local-variable 'comment-start)
238
238
(set (make-local-variable 'comment-start-skip)
240
(set (make-local-variable 'indent-line-function)
240
242
;; If we're using Emacs21, this makes flyspell work like it should
241
243
(when (boundp 'flyspell-generic-check-word-p)
242
244
(set (make-local-variable 'flyspell-generic-check-word-p)
722
726
(shell-quote-argument
723
727
(expand-file-name dir)))
724
728
muse-directories " ")))
725
(while (string-match "%W" str)
726
(setq str (replace-match string t t str)))
727
(while (string-match "%D" str)
728
(setq str (replace-match dirs t t str)))
729
(if (fboundp 'compilation-start)
730
(compilation-start str nil (lambda (&rest args) "*search*")
732
(and (fboundp 'compile-internal)
733
(compile-internal str "No more search hits" "search"
734
nil grep-regexp-alist)))))
729
(if (string= dirs "")
730
(muse-display-warning
731
"No directories were found in the current project; aborting search")
732
(while (string-match "%W" str)
733
(setq str (replace-match string t t str)))
734
(while (string-match "%D" str)
735
(setq str (replace-match dirs t t str)))
736
(if (fboundp 'compilation-start)
737
(compilation-start str nil (lambda (&rest args) "*search*")
739
(and (fboundp 'compile-internal)
740
(compile-internal str "No more search hits" "search"
741
nil grep-regexp-alist))))))
737
744
(defun muse-search-with-command (text)
851
859
(insert (concat "\n\n</" tag ">\n"))
852
860
(forward-line -2))))
862
;;; Muse list edit minor mode
864
(defvar muse-list-edit-minor-mode-map
865
(let ((map (make-sparse-keymap)))
866
(define-key map [(meta return)] 'muse-l-e-m-m-insert-list-item)
867
(define-key map [(control ?>)] 'muse-l-e-m-m-increase-list-item-indent)
868
(define-key map [(control ?<)] 'muse-l-e-m-m-decrease-list-item-indent)
871
"Keymap used by Muse list edit minor mode.")
873
(defvar muse-l-e-m-m-list-item-regexp
874
(concat "^%s\\(\\([^\n" muse-regexp-blank "].*?\\)?::"
875
"\\(?:[" muse-regexp-blank "]+\\|$\\)"
876
"\\|[" muse-regexp-blank "]?[-*+][" muse-regexp-blank "]*"
877
"\\|[" muse-regexp-blank "][0-9]+\\.[" muse-regexp-blank "]*\\)")
878
"Regexp used to match the beginning of a list item.
879
This is used by `muse-list-edit-minor-mode'.
880
The '%s' will be replaced with a whitespace regexp when publishing.")
882
(defun muse-l-e-m-m-insert-list-item ()
883
"Insert a list item at the current point, taking into account
884
your current list type and indentation level."
886
(let ((muse-list-item-regexp muse-l-e-m-m-list-item-regexp))
887
(call-interactively 'muse-insert-list-item)))
889
(defun muse-l-e-m-m-increase-list-item-indent ()
890
"Increase the indentation of the current list item."
892
(let ((muse-list-item-regexp muse-l-e-m-m-list-item-regexp))
893
(call-interactively 'muse-increase-list-item-indentation)))
895
(defun muse-l-e-m-m-decrease-list-item-indent ()
896
"Decrease the indentation of the current list item."
898
(let ((muse-list-item-regexp muse-l-e-m-m-list-item-regexp))
899
(call-interactively 'muse-decrease-list-item-indentation)))
901
(defvar muse-l-e-m-m-data nil
902
"A list of data that was changed by Muse list edit minor mode.")
903
(make-variable-buffer-local 'muse-l-e-m-m-data)
906
(define-minor-mode muse-list-edit-minor-mode
907
"This is a global minor mode for editing files with lists.
908
It is meant to be used with other major modes, and not with Muse mode.
910
Interactively, with no prefix argument, toggle the mode.
911
With universal prefix ARG turn mode on.
912
With zero or negative ARG turn mode off.
914
This minor mode provides the Muse keybindings for editing lists,
915
and support for filling lists properly.
917
It recognizes not only Muse-style lists, which use the \"-\"
918
character or numbers, but also lists that use asterisks or plus
919
signs. This should make the minor mode generally useful.
921
Definition lists and footnotes are also recognized.
923
Note that list items may omit leading spaces, for compatibility
924
with modes that set `left-margin', such as
925
`debian-changelog-mode'.
927
\\{muse-list-edit-minor-mode-map}"
930
:keymap muse-list-edit-minor-mode-map
933
(if (not muse-list-edit-minor-mode)
935
(when muse-l-e-m-m-data
936
(setq adaptive-fill-regexp (cdr (assoc "a-f-r" muse-l-e-m-m-data))
937
paragraph-start (cdr (assoc "p-s" muse-l-e-m-m-data))
938
fill-prefix (cdr (assoc "f-p" muse-l-e-m-m-data)))
939
(setq muse-l-e-m-m-data nil))
941
(unless muse-l-e-m-m-data
942
;; save previous fill-related data so we can restore it later
943
(setq muse-l-e-m-m-data
944
(list (cons "a-f-r" adaptive-fill-regexp)
945
(cons "p-s" paragraph-start)
946
(cons "f-p" fill-prefix))))
947
;; make fill work nicely with item lists
948
(let ((regexp (concat "\\s-*\\([-*+]\\|[0-9]+\\.\\)\\s-+"
949
"\\|\\[[0-9]+\\]\\s-*"
950
"\\|.*\\s-*::\\s-+")))
951
(set (make-local-variable 'adaptive-fill-regexp)
952
(concat regexp "\\|\\s-*"))
953
(set (make-local-variable 'paragraph-start)
954
(concat paragraph-start "\\|" regexp)))
955
;; force fill-prefix to be nil, because if it is a string that has
956
;; initial spaces, it messes up fill-paragraph's algorithm
957
(set (make-local-variable 'fill-prefix) nil)))
959
(defun turn-on-muse-list-edit-minor-mode ()
960
"Unconditionally turn on Muse list edit minor mode."
961
(muse-list-edit-minor-mode 1))
963
(defun turn-off-muse-list-edit-minor-mode ()
964
"Unconditionally turn off Muse list edit minor mode."
965
(muse-list-edit-minor-mode -1))
854
967
;;; muse-mode.el ends here