~ubuntu-branches/ubuntu/oneiric/muse-el/oneiric

« back to all changes in this revision

Viewing changes to lisp/muse-mode.el

  • Committer: Bazaar Package Importer
  • Author(s): Michael W. Olson (GNU address)
  • Date: 2008-01-09 15:51:46 UTC
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20080109155146-vkc4ohnzv96spdpm
Tags: upstream-3.11
ImportĀ upstreamĀ versionĀ 3.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 
7
7
;; Emacs Muse is free software; you can redistribute it and/or modify
8
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
 
9
;; by the Free Software Foundation; either version 3, or (at your
10
10
;; option) any later version.
11
11
 
12
12
;; Emacs Muse is distributed in the hope that it will be useful, but
143
143
 
144
144
    map))
145
145
 
 
146
;;; Muse mode
 
147
 
146
148
(defvar muse-mode-map
147
149
  (let ((map (make-sparse-keymap)))
148
150
    (define-key map [(control ?c) (control ?a)] 'muse-index)
197
199
    map)
198
200
  "Keymap used by Emacs Muse mode.")
199
201
 
200
 
;; Code:
201
 
 
202
202
;;;###autoload
203
203
(define-derived-mode muse-mode text-mode "Muse"
204
204
  "Muse is an Emacs mode for authoring and publishing documents.
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)
237
237
       "; ")
238
238
  (set (make-local-variable 'comment-start-skip)
239
239
       "^;\\s-+")
 
240
  (set (make-local-variable 'indent-line-function)
 
241
       #'ignore)
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)
301
303
  "See if point is on a blank line"
302
304
  (save-excursion
303
305
    (beginning-of-line)
304
 
    (looking-at (concat "[" muse-regexp-blank "]?[\n]+"))))
 
306
    (looking-at (concat "[" muse-regexp-blank "]*$"))))
305
307
 
306
308
(defun muse-get-paragraph-start ()
307
309
  "Return the start of the current paragraph. This function will
308
310
return nil if there are no prior paragraphs and the beginning of
309
311
the line if point is on a blank line."
310
 
  (let ((para-start (concat "[\n]+[" muse-regexp-blank "]?[\n]+")))
 
312
  (let ((para-start (concat "^[" muse-regexp-blank "]*$")))
311
313
    ;; search back to start of paragraph
312
314
    (save-excursion
313
315
      (save-match-data
578
580
                                            (cddr muse-current-project))
579
581
         current-prefix-arg))
580
582
  (setq style (muse-style style))
581
 
  (let ((result-path
582
 
         (muse-publish-output-file buffer-file-name
583
 
                                   (muse-style-element :path style) style)))
 
583
  (let* ((output-dir (muse-style-element :path style))
 
584
         (result-path (muse-publish-output-file buffer-file-name output-dir
 
585
                                                style))
 
586
         (muse-current-output-style (list :base (car style)
 
587
                                          :path output-dir)))
584
588
    (if (not (file-readable-p result-path))
585
589
        (error "Cannot open output file '%s'" result-path)
586
590
      (if other-window
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*")
731
 
                           grep-regexp-alist)
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*")
 
738
                             grep-regexp-alist)
 
739
        (and (fboundp 'compile-internal)
 
740
             (compile-internal str "No more search hits" "search"
 
741
                               nil grep-regexp-alist))))))
735
742
 
736
743
;;;###autoload
737
744
(defun muse-search-with-command (text)
821
828
  "Insert a tag interactively with a blank line after it."
822
829
  (interactive
823
830
   (list
824
 
    (completing-read
 
831
    (funcall
 
832
     muse-completing-read-function
825
833
     (concat "Tag: "
826
834
             (when muse-tag-history
827
835
               (concat "(default: " (car muse-tag-history) ") ")))
851
859
      (insert (concat "\n\n</" tag ">\n"))
852
860
      (forward-line -2))))
853
861
 
 
862
;;; Muse list edit minor mode
 
863
 
 
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)
 
869
 
 
870
    map)
 
871
  "Keymap used by Muse list edit minor mode.")
 
872
 
 
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.")
 
881
 
 
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."
 
885
  (interactive)
 
886
  (let ((muse-list-item-regexp muse-l-e-m-m-list-item-regexp))
 
887
    (call-interactively 'muse-insert-list-item)))
 
888
 
 
889
(defun muse-l-e-m-m-increase-list-item-indent ()
 
890
  "Increase the indentation of the current list item."
 
891
  (interactive)
 
892
  (let ((muse-list-item-regexp muse-l-e-m-m-list-item-regexp))
 
893
    (call-interactively 'muse-increase-list-item-indentation)))
 
894
 
 
895
(defun muse-l-e-m-m-decrease-list-item-indent ()
 
896
  "Decrease the indentation of the current list item."
 
897
  (interactive)
 
898
  (let ((muse-list-item-regexp muse-l-e-m-m-list-item-regexp))
 
899
    (call-interactively 'muse-decrease-list-item-indentation)))
 
900
 
 
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)
 
904
 
 
905
;;;###autoload
 
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.
 
909
 
 
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.
 
913
 
 
914
This minor mode provides the Muse keybindings for editing lists,
 
915
and support for filling lists properly.
 
916
 
 
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.
 
920
 
 
921
Definition lists and footnotes are also recognized.
 
922
 
 
923
Note that list items may omit leading spaces, for compatibility
 
924
with modes that set `left-margin', such as
 
925
`debian-changelog-mode'.
 
926
 
 
927
\\{muse-list-edit-minor-mode-map}"
 
928
  :init-value nil
 
929
  :lighter ""
 
930
  :keymap muse-list-edit-minor-mode-map
 
931
  :global nil
 
932
  :group 'muse-mode
 
933
  (if (not muse-list-edit-minor-mode)
 
934
      ;; deactivate
 
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))
 
940
    ;; activate
 
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)))
 
958
 
 
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))
 
962
 
 
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))
 
966
 
854
967
;;; muse-mode.el ends here