unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* 23.0.60; Input history and simplifications for ps-mode.el
@ 2008-06-04 19:08 Markus Triska
  2008-06-04 20:53 ` Chong Yidong
  0 siblings, 1 reply; 3+ messages in thread
From: Markus Triska @ 2008-06-04 19:08 UTC (permalink / raw)
  To: emacs-pretest-bug


This patch makes ps-mode derived from comint-mode, which yields an
input history for interactive use and allows a few simplifications.

2008-06-04  Markus Triska  <markus.triska@gmx.at>

	* progmodes/ps-mode.el (ps-run-mode-map): omit "\r", [return]
	(ps-mode-other-newline): simplify
	(ps-mode-center): "2 div neg" ==> "-2 div"
	(ps-run-mode): derive from comint-mode instead of
	fundamental-mode, yielding input history etc.
	(ps-run-start): adapt for comint-mode
	(ps-run-quit, ps-run-clear, ps-run-region, ps-run-boundingbox):
	omit "echo" parameter in call of ps-run-send-string
	(ps-run-send-string): adapt for comint-mode, remove "echo"
	parameter
	(ps-run-newline): remove now unneeded function


diff --git a/lisp/progmodes/ps-mode.el b/lisp/progmodes/ps-mode.el
index cb75142..9cd9019 100644
--- a/lisp/progmodes/ps-mode.el
+++ b/lisp/progmodes/ps-mode.el
@@ -39,6 +39,7 @@
 (defconst ps-mode-version "1.1h, 16 Jun 2005")
 (defconst ps-mode-maintainer-address "Peter Kleiweg <p.c.j.kleiweg@rug.nl>")
 
+(require 'comint)
 (require 'easymenu)
 
 ;; Define core `PostScript' group.
@@ -436,12 +437,11 @@ If nil, the following are tried in turn, until success:
 
 (unless ps-run-mode-map
   (setq ps-run-mode-map (make-sparse-keymap))
+  (set-keymap-parent ps-run-mode-map comint-mode-map)
   (define-key ps-run-mode-map "\C-c\C-q" 'ps-run-quit)
   (define-key ps-run-mode-map "\C-c\C-k" 'ps-run-kill)
   (define-key ps-run-mode-map "\C-c\C-e" 'ps-run-goto-error)
-  (define-key ps-run-mode-map [mouse-2] 'ps-run-mouse-goto-error)
-  (define-key ps-run-mode-map "\r" 'ps-run-newline)
-  (define-key ps-run-mode-map [return] 'ps-run-newline))
+  (define-key ps-run-mode-map [mouse-2] 'ps-run-mouse-goto-error))
 
 \f
 ;; Syntax table.
@@ -723,12 +723,9 @@ defines the beginning of a group. These tokens are:  {  [  <<"
   (blink-matching-open))
 
 (defun ps-mode-other-newline ()
-  "Perform newline in `*ps run*' buffer."
+  "Perform newline in `*ps-run*' buffer."
   (interactive)
-  (let ((buf (current-buffer)))
-    (set-buffer "*ps run*")
-    (ps-run-newline)
-    (set-buffer buf)))
+  (ps-run-send-string ""))
 
 \f
 ;; Print PostScript.
@@ -824,8 +821,8 @@ Only one `%' is removed, and it has to be in the first column."
   (insert "
 /center {
     dup stringwidth
-    exch 2 div neg
-    exch 2 div neg
+    exch -2 div
+    exch -2 div
     rmoveto
 } bind def
 "))
@@ -985,7 +982,7 @@ plus the usually uncoded characters inserted on positions 1 through 28."
 \f
 ;; Interactive PostScript interpreter.
 
-(define-derived-mode ps-run-mode fundamental-mode "Interactive PS"
+(define-derived-mode ps-run-mode comint-mode "Interactive PS"
   "Major mode in interactive PostScript window.
 This mode is invoked from `ps-mode' and should not be called directly.
 
@@ -1019,20 +1016,23 @@ This mode is invoked from `ps-mode' and should not be called directly.
       (setq init-file (ps-run-make-tmp-filename))
       (write-region (concat ps-run-init "\n") 0 init-file)
       (setq init-file (list init-file)))
-    (pop-to-buffer "*ps run*")
+    (pop-to-buffer "*ps-run*")
     (ps-run-mode)
     (when (process-status "ps-run")
       (delete-process "ps-run"))
     (erase-buffer)
     (setq command (append command init-file))
     (insert (mapconcat 'identity command " ") "\n")
-    (apply 'start-process "ps-run" "*ps run*" command)
+    (apply 'make-comint "ps-run" command)
+    (with-current-buffer "*ps-run*"
+      (use-local-map ps-run-mode-map)
+      (setq comint-prompt-regexp ps-run-prompt))
     (select-window oldwin)))
 
 (defun ps-run-quit ()
   "Quit interactive PostScript."
   (interactive)
-  (ps-run-send-string "quit" t)
+  (ps-run-send-string "quit")
   (ps-run-cleanup))
 
 (defun ps-run-kill ()
@@ -1044,9 +1044,9 @@ This mode is invoked from `ps-mode' and should not be called directly.
 (defun ps-run-clear ()
   "Clear/reset PostScript graphics."
   (interactive)
-  (ps-run-send-string "showpage" t)
+  (ps-run-send-string "showpage")
   (sit-for 1)
-  (ps-run-send-string "" t))
+  (ps-run-send-string ""))
 
 (defun ps-run-buffer ()
   "Send buffer to PostScript interpreter."
@@ -1061,7 +1061,7 @@ This mode is invoked from `ps-mode' and should not be called directly.
   (let ((f (ps-run-make-tmp-filename)))
     (set-marker ps-run-mark begin)
     (write-region begin end f)
-    (ps-run-send-string (format "(%s) run" f) t)))
+    (ps-run-send-string (format "(%s) run" f))))
 
 (defun ps-run-boundingbox ()
   "View BoundingBox."
@@ -1109,17 +1109,15 @@ grestore
 " x1 y1 x2 y1 x2 y2 x1 y2)
      0
      f)
-    (ps-run-send-string (format "(%s) run" f) t)
+    (ps-run-send-string (format "(%s) run" f))
     (set-buffer buf)))
 
-(defun ps-run-send-string (string &optional echo)
+(defun ps-run-send-string (string)
   (let ((oldwin (selected-window)))
-    (pop-to-buffer "*ps run*")
-    (goto-char (point-max))
-    (when echo
-      (insert string "\n"))
-    (set-marker (process-mark (get-process "ps-run")) (point))
-    (process-send-string "ps-run" (concat string "\n"))
+    (pop-to-buffer "*ps-run*")
+    (comint-goto-process-mark)
+    (insert string)
+    (comint-send-input)
     (select-window oldwin)))
 
 (defun ps-run-make-tmp-filename ()
@@ -1159,18 +1157,6 @@ grestore
   (mouse-set-point event)
   (ps-run-goto-error))
 
-(defun ps-run-newline ()
-  "Process newline in PostScript interpreter window."
-  (interactive)
-  (end-of-line)
-  (insert "\n")
-  (forward-line -1)
-  (when (looking-at ps-run-prompt)
-    (goto-char (match-end 0)))
-  (looking-at ".*")
-  (goto-char (1+ (match-end 0)))
-  (ps-run-send-string (buffer-substring (match-beginning 0) (match-end 0))))
-
 (defun ps-run-goto-error ()
   "Jump to buffer position read as integer at point.
 Use line numbers if `ps-run-error-line-numbers' is not nil"





In GNU Emacs 23.0.60.2 (i386-apple-darwin8.11.1, GTK+ Version 2.12.9)
 of 2008-06-03 on pnsgw3-client026.demo.tuwien.ac.at
Windowing system distributor `The XFree86 Project, Inc', version 11.0.40400000




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: 23.0.60; Input history and simplifications for ps-mode.el
  2008-06-04 19:08 23.0.60; Input history and simplifications for ps-mode.el Markus Triska
@ 2008-06-04 20:53 ` Chong Yidong
  2008-06-04 23:22   ` Markus Triska
  0 siblings, 1 reply; 3+ messages in thread
From: Chong Yidong @ 2008-06-04 20:53 UTC (permalink / raw)
  To: Markus Triska; +Cc: emacs-pretest-bug

Markus Triska <markus.triska@gmx.at> writes:

> This patch makes ps-mode derived from comint-mode, which yields an
> input history for interactive use and allows a few simplifications.

Looks OK to me.




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: 23.0.60; Input history and simplifications for ps-mode.el
  2008-06-04 20:53 ` Chong Yidong
@ 2008-06-04 23:22   ` Markus Triska
  0 siblings, 0 replies; 3+ messages in thread
From: Markus Triska @ 2008-06-04 23:22 UTC (permalink / raw)
  To: Chong Yidong; +Cc: emacs-pretest-bug


On top of the previous patch, please apply the following to make it work
correctly if the command has additional parameters:

diff --git a/lisp/progmodes/ps-mode.el b/lisp/progmodes/ps-mode.el
index 9cd9019..9eff050 100644
--- a/lisp/progmodes/ps-mode.el
+++ b/lisp/progmodes/ps-mode.el
@@ -1023,7 +1023,7 @@ This mode is invoked from `ps-mode' and should not be called directly.
     (erase-buffer)
     (setq command (append command init-file))
     (insert (mapconcat 'identity command " ") "\n")
-    (apply 'make-comint "ps-run" command)
+    (apply 'make-comint "ps-run" (car command) nil (cdr command))
     (with-current-buffer "*ps-run*"
       (use-local-map ps-run-mode-map)
       (setq comint-prompt-regexp ps-run-prompt))





^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-06-04 23:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-04 19:08 23.0.60; Input history and simplifications for ps-mode.el Markus Triska
2008-06-04 20:53 ` Chong Yidong
2008-06-04 23:22   ` Markus Triska

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).