Commit 65dab22a authored by David Byers's avatar David Byers
Browse files

Fixed bug 1281 and related issues

Detailed changes:
> 2004-02-27  David Byers  <byers@lysator.liu.se>
>
> 	* commands1.el (kom-write-comment): Use new def-kom-command
> 	features.
> 	(kom-private-answer): Ditto.
> 	(kom-write-footnote): Ditto.
> 	(kom-comment-previous): Ditto.
> 	(kom-private-answer): Ditto.
> 	(kom-private-answer-previous): Ditto.
>
> 	* slow.el (kom-slow-mode): Use def-kom-command instead of defun.
> 	(kom-quick-mode): Ditto.
>
> 	* commands2.el (kom-show-user-area): Use def-kom-command instead
> 	of defun.
>
> 	* command.el (def-kom-command): Added keyword support.
> 	(def-kom-emacs-command): Ditto.
> 	(lyskom-start-of-command): Added PROMPT-FORMAT.
>
parent 13709464
2004-02-27 David Byers <byers@lysator.liu.se>
* commands1.el (kom-write-comment): Use new def-kom-command
features.
(kom-private-answer): Ditto.
(kom-write-footnote): Ditto.
(kom-comment-previous): Ditto.
(kom-private-answer): Ditto.
(kom-private-answer-previous): Ditto.
* slow.el (kom-slow-mode): Use def-kom-command instead of defun.
(kom-quick-mode): Ditto.
* commands2.el (kom-show-user-area): Use def-kom-command instead
of defun.
* command.el (def-kom-command): Added keyword support.
(def-kom-emacs-command): Ditto.
(lyskom-start-of-command): Added PROMPT-FORMAT.
2004-02-23 David Byers <byers@lysator.liu.se>
Further reduce the likelihood of sending alarm messages
......
......@@ -65,33 +65,62 @@
(defmacro def-kom-command (cmd args doc interactive-decl &rest forms)
(if (not (stringp doc))
(progn (message "!! No docstring for command %S" cmd)
(setq forms (cons interactive-decl forms))
(setq interactive-decl doc)
(setq doc "")))
(if (not (eq (car interactive-decl) 'interactive))
(progn (message "!! Missing interactive declaration for %S; assuming \(interactive\)" cmd)
(setq forms (cons interactive-decl forms))
(setq interactive-decl '(interactive))))
(let ((bufsym (intern (format "%S-start-buffer" cmd))))
`(defun ,cmd ,args
,doc
,(lyskom-fix-interactive-decl interactive-decl cmd)
(let ((lyskom-command-point (point)))
(lyskom-start-of-command ',cmd)
(let ((,bufsym (current-buffer)))
(unwind-protect
(condition-case nil
(progn ,@forms)
(quit (ding)
(lyskom-insert-before-prompt
(lyskom-get-string 'interrupted))))
(lyskom-save-excursion
(when (buffer-live-p ,bufsym)
(set-buffer ,bufsym))
(lyskom-end-of-command))))))))
(defmacro def-kom-command (cmd args doc &rest forms)
"Define a LysKOM command CMD with args ARGS and docstring DOC.
This is like a defun for LysKOM commands. After the docstring you may
have a series of keywords that alter the behavior of the command,
followed by an interactive declaration (required) and the body of the
command.
The following keywords are recognized:
:dead-ok See the DEAD-OK paramter to lyskom-start-of-command
:may-interrupt See the MAY-INTERRUPT parameter to lyskom-start-of-command
:prompt-format See the PROMPT-FORMAT parameter to lyskom-start-of-command
Note that :prompt-format requires an argument."
(let (interactive-decl may-interrupt dead-ok prompt-format)
(while (memq (car forms) '(:prompt-format :dead-ok :may-interrupt))
(cond ((eq (car forms) :prompt-format)
(setq prompt-format (car (cdr forms)))
(setq forms (cdr forms)))
((eq (car forms) :dead-ok)
(setq dead-ok t))
((eq (car forms) :may-interrupt)
(setq may-interrupt t)))
(setq forms (cdr forms)))
(when (and (listp (car forms))
(eq 'interactive (car (car forms))))
(setq interactive-decl (car forms) forms (cdr forms)))
(if (not (stringp doc))
(progn (message "!! No docstring for command %S" cmd)
(setq forms (cons interactive-decl forms))
(setq interactive-decl doc)
(setq doc "")))
(if (not (eq (car interactive-decl) 'interactive))
(progn (message "!! Missing interactive declaration for %S; assuming \(interactive\)" cmd)
(setq forms (cons interactive-decl forms))
(setq interactive-decl '(interactive))))
(let ((bufsym (intern (format "%S-start-buffer" cmd))))
`(defun ,cmd ,args
,doc
,(lyskom-fix-interactive-decl interactive-decl cmd)
(let ((lyskom-command-point (point)))
(lyskom-start-of-command ',cmd ,may-interrupt ,dead-ok ,prompt-format)
(let ((,bufsym (current-buffer)))
(unwind-protect
(condition-case nil
(progn ,@forms)
(quit (ding)
(lyskom-insert-before-prompt
(lyskom-get-string 'interrupted))))
(lyskom-save-excursion
(when (buffer-live-p ,bufsym)
(set-buffer ,bufsym))
(lyskom-end-of-command)))))))))
;;
;; def-kom-emacs-command works like def-kom-command, but the template
......@@ -122,39 +151,54 @@
;; (and kom-cmd-running-as-kom-command (lyskom-end-of-command)))))
;;
(defmacro def-kom-emacs-command (cmd args doc interactive-decl &rest forms)
(if (not (stringp doc))
(progn (message "!! No docstring for command %S" cmd)
(setq forms (cons interactive-decl forms))
(setq interactive-decl doc)
(setq doc "")))
(if (not (eq (car interactive-decl) 'interactive))
(progn (message "!! Missing interactive declaration for %S; assuming \(interactive\)" cmd)
(setq forms (cons interactive-decl forms))
(setq interactive-decl '(interactive))))
(let ((rsym (intern (format "%S-running-as-kom-command" cmd)))
(bufsym (intern (format "%S-start-buffer" cmd))))
`(defun ,cmd ,args
,doc
,(lyskom-fix-interactive-decl interactive-decl cmd)
(let ((,rsym nil))
(condition-case nil
(progn (lyskom-start-of-command ',cmd)
(setq ,rsym t))
(error nil))
(let ((,bufsym (current-buffer)))
(unwind-protect
(condition-case nil
(progn ,@forms)
(quit (ding)
(lyskom-insert-before-prompt
(lyskom-get-string 'interrupted))))
(and ,rsym
(lyskom-save-excursion
(when (buffer-live-p ,bufsym)
(set-buffer ,bufsym))
(lyskom-end-of-command)))))))))
(defmacro def-kom-emacs-command (cmd args doc &rest forms)
(let (interactive-decl may-interrupt dead-ok prompt-format)
(while (memq (car forms) '(:prompt-format :dead-ok :may-interrupt))
(cond ((eq (car forms) :prompt-format)
(setq prompt-format (car (cdr forms)))
(setq forms (cdr forms)))
((eq (car forms) :dead-ok)
(setq dead-ok t))
((eq (car forms) :may-interrupt)
(setq may-interrupt t)))
(setq forms (cdr forms)))
(when (and (listp (car forms))
(eq 'interactive (car (car forms))))
(setq interactive-decl (car forms) forms (cdr forms)))
(if (not (stringp doc))
(progn (message "!! No docstring for command %S" cmd)
(setq forms (cons interactive-decl forms))
(setq interactive-decl doc)
(setq doc "")))
(if (not (eq (car interactive-decl) 'interactive))
(progn (message "!! Missing interactive declaration for %S; assuming \(interactive\)" cmd)
(setq forms (cons interactive-decl forms))
(setq interactive-decl '(interactive))))
(let ((rsym (intern (format "%S-running-as-kom-command" cmd)))
(bufsym (intern (format "%S-start-buffer" cmd))))
`(defun ,cmd ,args
,doc
,(lyskom-fix-interactive-decl interactive-decl cmd)
(let ((,rsym nil))
(condition-case nil
(progn (lyskom-start-of-command ',cmd ,may-interrupt ,dead-ok ,prompt-format)
(setq ,rsym t))
(error nil))
(let ((,bufsym (current-buffer)))
(unwind-protect
(condition-case nil
(progn ,@forms)
(quit (ding)
(lyskom-insert-before-prompt
(lyskom-get-string 'interrupted))))
(and ,rsym
(lyskom-save-excursion
(when (buffer-live-p ,bufsym)
(set-buffer ,bufsym))
(lyskom-end-of-command))))))))))
......@@ -488,7 +532,7 @@ and back of the string."
;;; (minibuffer-complete-word))
(defun lyskom-start-of-command (function &optional may-interrupt dead-ok)
(defun lyskom-start-of-command (function &optional may-interrupt dead-ok prompt-format)
"This function is run at the beginning of every LysKOM command.
It moves the cursor one line down, and +++ later it will tell the server
that the previous text has been read.
......@@ -503,6 +547,10 @@ don't signal an error if this call is interrupting another command.
If optional DEAD-OK is non-nil, don't signal an error if the session
has been closed.
If optional PROMPT-FORMAT is non-nil, this will be used to format the prompt.
It should be a format string suitable for lyskom-format. Argument one is the
command name (a symbol or string).
Special: if lyskom-is-waiting then we are allowed to break if we set
lyskom-is-waiting nil.
......@@ -534,9 +582,10 @@ chosen according to this"
(cond
(lyskom-first-time-around)
((stringp function) (lyskom-insert function))
((and function (symbolp function))
(let ((name (lyskom-command-name function)))
(if name (lyskom-insert name)))))
((lyskom-command-name function)
(if prompt-format
(lyskom-format-insert prompt-format function)
(lyskom-insert (lyskom-command-name function)))))
(save-excursion
(if lyskom-current-prompt
(let ((inhibit-read-only t))
......
......@@ -1036,7 +1036,7 @@ This does lyskom-end-of-command"
;;; FIXME: Does not use def-kom-command
(defun kom-write-comment (text-no)
(def-kom-command kom-write-comment (text-no)
"Write a comment to the selected text.
Several settings affect writing texts in general.
......@@ -1046,36 +1046,32 @@ recipients are handled.
This command accepts text number prefix arguments (see
`lyskom-read-text-no-prefix-arg')."
(interactive (list
(let ((lyskom-current-command 'kom-write-comment))
(lyskom-read-text-no-prefix-arg 'what-comment-no))))
(lyskom-start-of-command (concat
(lyskom-command-name 'kom-write-comment)
(if text-no
(lyskom-format " (%#1n)" text-no)
"")))
(unwind-protect
(if text-no
(progn
(lyskom-nag-about-presentation)
(blocking-do-multiple ((text (get-text text-no))
(text-stat (get-text-stat text-no)))
(when (or (null (text-stat-find-aux text-stat 4))
(lyskom-j-or-n-p
(lyskom-get-string 'no-comments-q)))
(if (and (text-stat-find-aux text-stat 5)
(lyskom-j-or-n-p
(lyskom-get-string 'private-answer-q)))
(lyskom-private-answer-soon
text-stat
text
text-no)
(lyskom-write-comment-soon text-stat
text
text-no
'comment)))))
(lyskom-insert-string 'confusion-who-to-reply-to))
(lyskom-end-of-command)))
:prompt-format (concat "%#1C " (if text-no
(lyskom-format " (%#1n)" text-no)
""))
(interactive (list (let ((lyskom-current-command 'kom-write-comment))
(lyskom-read-text-no-prefix-arg 'what-comment-no))))
(if text-no
(progn
(lyskom-nag-about-presentation)
(blocking-do-multiple ((text (get-text text-no))
(text-stat (get-text-stat text-no)))
(when (or (null (text-stat-find-aux text-stat 4))
(lyskom-j-or-n-p
(lyskom-get-string 'no-comments-q)))
(if (and (text-stat-find-aux text-stat 5)
(lyskom-j-or-n-p
(lyskom-get-string 'private-answer-q)))
(lyskom-private-answer-soon
text-stat
text
text-no)
(lyskom-write-comment-soon text-stat
text
text-no
'comment)))))
(lyskom-insert-string 'confusion-who-to-reply-to)))
(def-kom-command kom-write-footnote (text-no)
......@@ -1092,6 +1088,9 @@ This command accepts text number prefix arguments (see
`lyskom-read-text-no-prefix-arg'). Without a prefix argument this
command will write a footnote to the most recently read or written
applicable text."
:prompt-format (concat "%#1C " (if text-no
(lyskom-format " (%#1n)" text-no)
""))
(interactive (list (lyskom-read-text-no-prefix-arg 'what-footnote-no nil
'last-seen-written)))
(if text-no
......@@ -1113,6 +1112,9 @@ recipients are handled.
This command accepts text number prefix arguments (see
`lyskom-read-text-no-prefix-arg')."
:prompt-format (concat "%#1C " (if text-no
(lyskom-format " (%#1n)" text-no)
""))
(interactive (list (lyskom-read-text-no-prefix-arg 'what-comment-no nil
lyskom-previous-text)))
(if text-no
......@@ -1292,6 +1294,9 @@ recipients are handled.
This command accepts text number prefix arguments (see
`lyskom-read-text-no-prefix-arg')."
:prompt-format (concat "%#1C " (if text-no
(lyskom-format " (%#1n)" text-no)
""))
(interactive (list (lyskom-read-text-no-prefix-arg 'what-private-no)))
(if text-no
(blocking-do-multiple ((text-stat (get-text-stat text-no))
......@@ -1367,6 +1372,9 @@ recipients are handled.
This command accepts text number prefix arguments (see
`lyskom-read-text-no-prefix-arg')."
:prompt-format (concat "%#1C " (if text-no
(lyskom-format " (%#1n)" text-no)
""))
(interactive (list (lyskom-read-text-no-prefix-arg 'what-private-no nil
lyskom-previous-text)))
(if text-no
......
......@@ -2072,17 +2072,16 @@ not function names."
;;;
;;; Author: David Byers
(defun kom-show-user-area ()
(def-kom-command kom-show-user-area ()
"Get and display the user area of the current person. The user area
is a regular text used to store all settings. The format of this text
is documented in the LysKOM protocol specification. This command is
primarily intended for use by developers."
(interactive)
(lyskom-start-of-command 'kom-show-user-area)
(let ((pers-stat (blocking-do 'get-pers-stat lyskom-pers-no)))
(lyskom-view-text (pers-stat->user-area pers-stat)
nil nil nil nil nil)
(lyskom-run 'main 'lyskom-end-of-command)))
(lyskom-wait-queue 'main)))
;;;============================================================
......
......@@ -228,28 +228,24 @@ If the completion was not exact it returns nil."
'lyskom-complete-command))))
(defun kom-slow-mode ()
(def-kom-command kom-slow-mode ()
"Starts the slow-command-mode. In this mode you write commands in the
main LysKOM buffer instead of using keyboard shortcuts."
(interactive)
(lyskom-start-of-command 'kom-slow-mode)
(unless lyskom-slow-mode
(setq lyskom-saved-read-only buffer-read-only)
(setq lyskom-slow-mode t)
(setq buffer-read-only nil)
(use-local-map lyskom-slow-mode-map))
(lyskom-end-of-command))
(use-local-map lyskom-slow-mode-map)))
(defun kom-quick-mode ()
(def-kom-command kom-quick-mode ()
"Starts the quick command mode. This is the standard mode for LysKOM,
where you use keyboard shortcuts for most commands, and the \"x\" prefix
for all other commands."
(interactive)
(lyskom-start-of-command 'kom-quick-mode)
(when lyskom-slow-mode
(setq buffer-read-only lyskom-saved-read-only)
(setq lyskom-slow-mode nil)
(use-local-map lyskom-mode-map))
(lyskom-end-of-command))
(use-local-map lyskom-mode-map)))
......@@ -2174,7 +2174,7 @@ Nuvarande r
(kom-who-am-i . "Var (r) jag")
(kom-list-clients . "Lista klienter")
(kom-busy-wait . "Vnta p ett inlgg")
(kom-write-comment . "Kommentera inlgget")
(kom-write-comment . "Kommentera inlgg")
(kom-comment-previous . "Kommentera fregende inlgg")
(kom-write-footnote . "Fotnot till inlgg")
(kom-private-answer . "Personligt svar")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment