aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2006-09-06 17:34:12 +0000
committerStefan Monnier2006-09-06 17:34:12 +0000
commitd364dee6ba29f72f1ed1e715043e865af5fc98ef (patch)
tree7d131f9d737e2e4dd6d75d2d6d7334b420845160
parent4a3608f5045e534b19020fc4767b7635ebc8d3e4 (diff)
downloademacs-d364dee6ba29f72f1ed1e715043e865af5fc98ef.tar.gz
emacs-d364dee6ba29f72f1ed1e715043e865af5fc98ef.zip
Remove * in docstrings.
(prolog-program-name): Add SWI prolog. (prolog-mode-menu): New menu. (prolog-mode): Set comment-add. (prolog-indent-line): Simplify. Use indent-line-to. (inferior-prolog-buffer): New var. (inferior-prolog-run, inferior-prolog-process): New funs. (run-prolog, switch-to-prolog): Rewrite, using them. (prolog-consult-region): Use inferior-prolog-buffer. (inferior-prolog-load-file): New function. (prolog-mode-map): Add bindings for load-file and switch-to-prolog.
-rw-r--r--lisp/ChangeLog12
-rw-r--r--lisp/progmodes/prolog.el125
2 files changed, 107 insertions, 30 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 1c75e6ec602..aa2fb64ad60 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,17 @@
12006-09-06 Stefan Monnier <monnier@iro.umontreal.ca> 12006-09-06 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * progmodes/prolog.el: Remove * in docstrings.
4 (prolog-program-name): Add SWI prolog.
5 (prolog-mode-menu): New menu.
6 (prolog-mode): Set comment-add.
7 (prolog-indent-line): Simplify. Use indent-line-to.
8 (inferior-prolog-buffer): New var.
9 (inferior-prolog-run, inferior-prolog-process): New funs.
10 (run-prolog, switch-to-prolog): Rewrite, using them.
11 (prolog-consult-region): Use inferior-prolog-buffer.
12 (inferior-prolog-load-file): New function.
13 (prolog-mode-map): Add bindings for load-file and switch-to-prolog.
14
3 * textmodes/fill.el (fill-single-word-nobreak-p): Allow breaking before 15 * textmodes/fill.el (fill-single-word-nobreak-p): Allow breaking before
4 last word, if it's not the end of the paragraph. 16 last word, if it's not the end of the paragraph.
5 17
diff --git a/lisp/progmodes/prolog.el b/lisp/progmodes/prolog.el
index 14b47475eb1..7bb8c3a3f40 100644
--- a/lisp/progmodes/prolog.el
+++ b/lisp/progmodes/prolog.el
@@ -41,27 +41,27 @@
41 41
42 42
43(defcustom prolog-program-name 43(defcustom prolog-program-name
44 (let ((names '("prolog" "gprolog"))) 44 (let ((names '("prolog" "gprolog" "swipl")))
45 (while (and names 45 (while (and names
46 (not (executable-find (car names)))) 46 (not (executable-find (car names))))
47 (setq names (cdr names))) 47 (setq names (cdr names)))
48 (or (car names) "prolog")) 48 (or (car names) "prolog"))
49 "*Program name for invoking an inferior Prolog with `run-prolog'." 49 "Program name for invoking an inferior Prolog with `run-prolog'."
50 :type 'string 50 :type 'string
51 :group 'prolog) 51 :group 'prolog)
52 52
53(defcustom prolog-consult-string "reconsult(user).\n" 53(defcustom prolog-consult-string "reconsult(user).\n"
54 "*(Re)Consult mode (for C-Prolog and Quintus Prolog). " 54 "(Re)Consult mode (for C-Prolog and Quintus Prolog). "
55 :type 'string 55 :type 'string
56 :group 'prolog) 56 :group 'prolog)
57 57
58(defcustom prolog-compile-string "compile(user).\n" 58(defcustom prolog-compile-string "compile(user).\n"
59 "*Compile mode (for Quintus Prolog)." 59 "Compile mode (for Quintus Prolog)."
60 :type 'string 60 :type 'string
61 :group 'prolog) 61 :group 'prolog)
62 62
63(defcustom prolog-eof-string "end_of_file.\n" 63(defcustom prolog-eof-string "end_of_file.\n"
64 "*String that represents end of file for Prolog. 64 "String that represents end of file for Prolog.
65When nil, send actual operating system end of file." 65When nil, send actual operating system end of file."
66 :type 'string 66 :type 'string
67 :group 'prolog) 67 :group 'prolog)
@@ -121,7 +121,21 @@ When nil, send actual operating system end of file."
121(defvar prolog-mode-map 121(defvar prolog-mode-map
122 (let ((map (make-sparse-keymap))) 122 (let ((map (make-sparse-keymap)))
123 (define-key map "\e\C-x" 'prolog-consult-region) 123 (define-key map "\e\C-x" 'prolog-consult-region)
124 (define-key map "\C-c\C-l" 'inferior-prolog-load-file)
125 (define-key map "\C-c\C-z" 'switch-to-prolog)
124 map)) 126 map))
127
128(easy-menu-define prolog-mode-menu prolog-mode-map "Menu for Prolog mode."
129 ;; Mostly copied from scheme-mode's menu.
130 ;; Not tremendously useful, but it's a start.
131 '("Prolog"
132 ["Indent line" indent-according-to-mode t]
133 ["Indent region" indent-region t]
134 ["Comment region" comment-region t]
135 ["Uncomment region" uncomment-region t]
136 "--"
137 ["Run interactive Prolog session" run-prolog t]
138 ))
125 139
126;;;###autoload 140;;;###autoload
127(defun prolog-mode () 141(defun prolog-mode ()
@@ -138,29 +152,24 @@ if that value is non-nil."
138 (setq major-mode 'prolog-mode) 152 (setq major-mode 'prolog-mode)
139 (setq mode-name "Prolog") 153 (setq mode-name "Prolog")
140 (prolog-mode-variables) 154 (prolog-mode-variables)
155 (set (make-local-variable 'comment-add) 1)
141 ;; font lock 156 ;; font lock
142 (setq font-lock-defaults '(prolog-font-lock-keywords 157 (setq font-lock-defaults '(prolog-font-lock-keywords
143 nil nil nil 158 nil nil nil
144 beginning-of-line)) 159 beginning-of-line))
145 (run-mode-hooks 'prolog-mode-hook)) 160 (run-mode-hooks 'prolog-mode-hook))
146 161
147(defun prolog-indent-line (&optional whole-exp) 162(defun prolog-indent-line ()
148 "Indent current line as Prolog code. 163 "Indent current line as Prolog code.
149With argument, indent any additional lines of the same clause 164With argument, indent any additional lines of the same clause
150rigidly along with this one (not yet)." 165rigidly along with this one (not yet)."
151 (interactive "p") 166 (interactive "p")
152 (let ((indent (prolog-indent-level)) 167 (let ((indent (prolog-indent-level))
153 (pos (- (point-max) (point))) beg) 168 (pos (- (point-max) (point))))
154 (beginning-of-line) 169 (beginning-of-line)
155 (setq beg (point)) 170 (indent-line-to indent)
156 (skip-chars-forward " \t")
157 (if (zerop (- indent (current-column)))
158 nil
159 (delete-region beg (point))
160 (indent-to indent))
161 (if (> (- (point-max) pos) (point)) 171 (if (> (- (point-max) pos) (point))
162 (goto-char (- (point-max) pos))) 172 (goto-char (- (point-max) pos)))))
163 ))
164 173
165(defun prolog-indent-level () 174(defun prolog-indent-level ()
166 "Compute Prolog indentation level." 175 "Compute Prolog indentation level."
@@ -256,27 +265,73 @@ Return not at end copies rest of line to end and sends it.
256 (setq comint-prompt-regexp "^| [ ?][- ] *") 265 (setq comint-prompt-regexp "^| [ ?][- ] *")
257 (prolog-mode-variables)) 266 (prolog-mode-variables))
258 267
268(defvar inferior-prolog-buffer nil)
269
270(defun inferior-prolog-run (&optional name)
271 (with-current-buffer (make-comint "prolog" (or name prolog-program-name))
272 (inferior-prolog-mode)
273 (setq-default inferior-prolog-buffer (current-buffer))
274 (make-local-variable 'inferior-prolog-buffer)
275 (when (and name (not (equal name prolog-program-name)))
276 (set (make-local-variable 'prolog-program-name) name))
277 (set (make-local-variable 'inferior-prolog-flavor)
278 ;; Force re-detection.
279 (let* ((proc (get-buffer-process (current-buffer)))
280 (pmark (and proc (marker-position (process-mark proc)))))
281 (cond
282 ((null pmark) (1- (point-min)))
283 ;; The use of insert-before-markers in comint.el together with
284 ;; the potential use of comint-truncate-buffer in the output
285 ;; filter, means that it's difficult to reliably keep track of
286 ;; the buffer position where the process's output started.
287 ;; If possible we use a marker at "start - 1", so that
288 ;; insert-before-marker at `start' won't shift it. And if not,
289 ;; we fall back on using a plain integer.
290 ((> pmark (point-min)) (copy-marker (1- pmark)))
291 (t (1- pmark)))))
292 (add-hook 'comint-output-filter-functions
293 'inferior-prolog-guess-flavor nil t)))
294
295(defun inferior-prolog-process (&optional dontstart)
296 (or (and (buffer-live-p inferior-prolog-buffer)
297 (get-buffer-process inferior-prolog-buffer))
298 (unless dontstart
299 (inferior-prolog-run)
300 ;; Try again.
301 (inferior-prolog-process))))
302
259;;;###autoload 303;;;###autoload
260(defun run-prolog () 304(defalias 'run-prolog 'switch-to-prolog)
261 "Run an inferior Prolog process, input and output via buffer *prolog*." 305;;;###autoload
262 (interactive) 306(defun switch-to-prolog (&optional name)
263 (require 'comint) 307 "Run an inferior Prolog process, input and output via buffer *prolog*.
264 (pop-to-buffer (make-comint "prolog" prolog-program-name)) 308With prefix argument \\[universal-prefix], prompt for the program to use."
265 (inferior-prolog-mode)) 309 (interactive
310 (list (when current-prefix-arg
311 (let ((proc (inferior-prolog-process 'dontstart)))
312 (if proc
313 (if (yes-or-no-p "Kill current process before starting new one? ")
314 (kill-process proc)
315 (error "Abort")))
316 (read-string "Run Prolog: " prolog-program-name)))))
317 (unless (inferior-prolog-process 'dontstart)
318 (inferior-prolog-run name))
319 (pop-to-buffer inferior-prolog-buffer))
266 320
267(defun prolog-consult-region (compile beg end) 321(defun prolog-consult-region (compile beg end)
268 "Send the region to the Prolog process made by \"M-x run-prolog\". 322 "Send the region to the Prolog process made by \"M-x run-prolog\".
269If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode." 323If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode."
270 (interactive "P\nr") 324 (interactive "P\nr")
271 (save-excursion 325 (let ((proc (inferior-prolog-process)))
272 (if compile 326 (comint-send-string proc
273 (process-send-string "prolog" prolog-compile-string) 327 (if compile prolog-compile-string
274 (process-send-string "prolog" prolog-consult-string)) 328 prolog-consult-string))
275 (process-send-region "prolog" beg end) 329 (comint-send-region proc beg end)
276 (process-send-string "prolog" "\n") ;May be unnecessary 330 (comint-send-string proc "\n") ;May be unnecessary
277 (if prolog-eof-string 331 (if prolog-eof-string
278 (process-send-string "prolog" prolog-eof-string) 332 (comint-send-string proc prolog-eof-string)
279 (process-send-eof "prolog")))) ;Send eof to prolog process. 333 (with-current-buffer (process-buffer proc)
334 (comint-send-eof))))) ;Send eof to prolog process.
280 335
281(defun prolog-consult-region-and-go (compile beg end) 336(defun prolog-consult-region-and-go (compile beg end)
282 "Send the region to the inferior Prolog, and switch to *prolog* buffer. 337 "Send the region to the inferior Prolog, and switch to *prolog* buffer.
@@ -285,7 +340,17 @@ If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode."
285 (prolog-consult-region compile beg end) 340 (prolog-consult-region compile beg end)
286 (switch-to-buffer "*prolog*")) 341 (switch-to-buffer "*prolog*"))
287 342
343(defun inferior-prolog-load-file ()
344 "Pass the current buffer's file to the inferior prolog process."
345 (interactive)
346 (save-buffer)
347 (let ((file buffer-file-name)
348 (proc (inferior-prolog-process)))
349 (with-current-buffer (process-buffer proc)
350 (comint-send-string proc (concat "['" (file-relative-name file) "'].\n"))
351 (pop-to-buffer (current-buffer)))))
352
288(provide 'prolog) 353(provide 'prolog)
289 354
290;;; arch-tag: f3ec6748-1272-4ab6-8826-c50cb1607636 355;; arch-tag: f3ec6748-1272-4ab6-8826-c50cb1607636
291;;; prolog.el ends here 356;;; prolog.el ends here