96
99
(defun muse-update-file-extension (sym val)
97
100
"Update the value of `muse-file-extension'."
98
(when (and (featurep 'muse-mode)
99
(boundp sym) (stringp (symbol-value sym))
100
(or (not (stringp val))
101
(not (string= (symbol-value sym) val))))
102
;; remove old auto-mode-alist association
103
(setq auto-mode-alist
104
(delete (cons (concat "\\." (symbol-value sym) "\\'")
105
'muse-mode-choose-mode)
108
;; associate the new file extension with muse-mode
109
(when (and (featurep 'muse-mode)
111
(or (not (stringp (symbol-value sym)))
112
(not (string= (symbol-value sym) val))))
113
(add-to-list 'auto-mode-alist
114
(cons (concat "\\." val "\\'")
115
'muse-mode-choose-mode)))
116
;; update the ignored extensions regexp
117
(when (and (fboundp 'muse-update-ignored-extensions-regexp)
118
(or (not (stringp (symbol-value sym)))
120
(not (string= (symbol-value sym) val))))
121
(muse-update-ignored-extensions-regexp
122
'muse-ignored-extensions muse-ignored-extensions)))
101
(let ((old (and (boundp sym) (symbol-value sym))))
103
(when (and (featurep 'muse-mode)
104
(or (not (stringp val))
106
(not (string= old val))))
107
;; remove old auto-mode-alist association
108
(when (and (boundp sym) (stringp old))
109
(setq auto-mode-alist
110
(delete (cons (concat "\\." old "\\'")
111
'muse-mode-choose-mode)
113
;; associate the new file extension with muse-mode
115
(add-to-list 'auto-mode-alist
116
(cons (concat "\\." val "\\'")
117
'muse-mode-choose-mode)))
118
;; update the ignored extensions regexp
119
(when (fboundp 'muse-update-ignored-extensions-regexp)
120
(muse-update-ignored-extensions-regexp
121
'muse-ignored-extensions muse-ignored-extensions)))))
124
123
(defcustom muse-file-extension "muse"
125
124
"File extension of Muse files. Omit the period at the beginning.
162
167
(defun muse-update-file-extension-after-init ()
163
168
;; This is short, but it has to be a function, otherwise Emacs21
164
169
;; does not load it properly when running after-init-hook
165
(muse-update-file-extension 'muse-file-extension muse-file-extension))
170
(unless (string= muse-file-extension "muse")
171
(let ((val muse-file-extension)
172
(muse-file-extension "muse"))
173
(muse-update-file-extension 'muse-file-extension val))))
167
175
;; Once the user's init file has been processed, determine whether
168
176
;; they want a file extension
250
261
"Create a temporary buffer, and evaluate BODY there like `progn'.
251
262
See also `with-temp-file' and `with-output-to-string'.
253
Unlike `with-temp-buffer', this will never attempt to save the temp buffer.
254
It is meant to be used along with `insert-file-contents'.
264
Unlike `with-temp-buffer', this will never attempt to save the
265
temp buffer. It is meant to be used along with
266
`insert-file-contents' or `muse-insert-file-contents'.
256
268
Additionally, if `debug-on-error' is set to t, keep the buffer
257
269
around for debugging purposes rather than removing it."
284
296
(put 'muse-with-temp-buffer 'lisp-indent-function 0)
285
297
(put 'muse-with-temp-buffer 'edebug-form-spec '(body))
299
(defun muse-insert-file-contents (filename &optional visit)
300
"Insert the contents of file FILENAME after point.
301
Do character code conversion, but none of the other unnecessary
302
things like format decoding or `find-file-hook'.
304
If VISIT is non-nil, the buffer's visited filename
305
and last save file modtime are set, and it is marked unmodified.
306
If visiting and the file does not exist, visiting is completed
307
before the error is signaled."
308
(let ((format-alist nil)
309
(after-insert-file-functions nil)
310
(find-buffer-file-type-function
311
(if (fboundp 'find-buffer-file-type)
312
(symbol-function 'find-buffer-file-type)
314
(inhibit-file-name-handlers
315
(append '(jka-compr-handler image-file-handler)
316
inhibit-file-name-handlers))
317
(inhibit-file-name-operation 'insert-file-contents))
320
(fset 'find-buffer-file-type (lambda (filename) t))
321
(insert-file-contents filename visit))
322
(if find-buffer-file-type-function
323
(fset 'find-buffer-file-type find-buffer-file-type-function)
324
(fmakunbound 'find-buffer-file-type)))))
326
(defun muse-write-file (filename)
327
"Write current buffer into file FILENAME.
328
Unlike `write-file', this does not visit the file, try to back it
329
up, or interact with vc.el in any way.
331
If the file was not written successfully, return nil. Otherwise,
333
(let ((backup-inhibited t)
334
(buffer-file-name filename)
335
(buffer-file-truename (file-truename filename)))
339
(if (not (file-writable-p buffer-file-name))
341
(muse-display-warning
342
(format "Cannot write file %s:\n %s" buffer-file-name
343
(let ((dir (file-name-directory buffer-file-name)))
344
(if (not (file-directory-p dir))
345
(if (file-exists-p dir)
346
(format "%s is not a directory" dir)
347
(format "No directory named %s exists" dir))
348
(if (not (file-exists-p buffer-file-name))
349
(format "Directory %s write-protected" dir)
350
"File is write-protected"))))))
351
(let ((coding-system-for-write
352
(or (and (boundp 'save-buffer-coding-system)
353
save-buffer-coding-system)
354
coding-system-for-write)))
355
(write-region (point-min) (point-max) buffer-file-name))
356
(when (boundp 'last-file-coding-system-used)
357
(when (boundp 'buffer-file-coding-system-explicit)
358
(setq buffer-file-coding-system-explicit
359
last-coding-system-used))
360
(if save-buffer-coding-system
361
(setq save-buffer-coding-system last-coding-system-used)
362
(setq buffer-file-coding-system last-coding-system-used)))
287
365
(defun muse-collect-alist (list element &optional test)
288
366
"Collect items from LIST whose car is equal to ELEMENT.
289
367
If TEST is specified, use it to compare ELEMENT."
761
848
(match-found nil))
762
849
(while (and (> nesting 0)
763
850
(setq match-found (re-search-forward tag-regexp nil t)))
764
(if (string-equal (match-string 2) "/")
765
(setq nesting (1- nesting))
766
(setq nesting (1+ nesting))))
851
;; for the sake of font-locking code, skip matches in comments
852
(unless (get-text-property (match-beginning 0) 'muse-comment)
853
(if (string-equal (match-string 2) "/")
854
(setq nesting (1- nesting))
855
(setq nesting (1+ nesting)))))
769
858
;;; muse.el ends here