Commit 121344d2 authored by David Byers's avatar David Byers
Browse files

Hantera klickbara saker i långsamma kommandon.

Bättre utfyllnad av kommandon.
parent 19cf057d
2000-09-01 David Byers <davby@ida.liu.se>
* command.el (lyskom-complete-command): Fix. We didn't handle
check for exact match properly. Fix unibyte incompatibility.
(lyskom-read-extended-command): Use lyskom-complete-command.
(lyskom-ok-command): Work the elements from
lyskom-command-alternatives.
* vars.el.in (lyskom-command-alternatives): Made a minibuffer
variable.
(lyskom-is-administrator): Same here.
* command.el (lyskom-ok-command): Rewrote to work with new
completion thingy.
Buttons and menus in slow mode:
* slow.el (kom-expand-slow-command-or-next-link): New command.
(kom-slow-click-or-yank): New command.
(kom-slow-button-press): New command.
(kom-slow-menu-button-press): New command.
(kom-expand-slow-command-or-next-link): New command.
(lyskom-slow-on-prompt-line): New function.
2000-08-31 David Byers <davby@ida.liu.se>
* slow.el (kom-slow-start-of-line): Do the right thing when not on
the last line of the buffer.
2000-08-31 Ulrik Haugen <qha@lysator.liu.se> 2000-08-31 Ulrik Haugen <qha@lysator.liu.se>
* lyskom-rest.el (lyskom-trim-buffer): Saves point and mark and * lyskom-rest.el (lyskom-trim-buffer): Saves point and mark and
......
...@@ -190,9 +190,8 @@ ...@@ -190,9 +190,8 @@
(defun lyskom-ok-command (alternative administrator) (defun lyskom-ok-command (alternative administrator)
"Returns non-nil if it is ok to do such a command right now." "Returns non-nil if it is ok to do such a command right now."
(if administrator (if administrator
(not (memq (cdr alternative) lyskom-admin-removed-commands)) (not (memq (elt alternative 1) lyskom-admin-removed-commands))
(not (memq (cdr alternative) lyskom-noadmin-removed-commands)))) (not (memq (elt alternative 1) lyskom-noadmin-removed-commands))))
(defun kom-extended-command () (defun kom-extended-command ()
"Read a LysKOM function name and call the function." "Read a LysKOM function name and call the function."
...@@ -206,45 +205,44 @@ ...@@ -206,45 +205,44 @@
"Reads and returns a command" "Reads and returns a command"
(let* ((completion-ignore-case t) (let* ((completion-ignore-case t)
(minibuffer-setup-hook minibuffer-setup-hook) (minibuffer-setup-hook minibuffer-setup-hook)
(alternatives (mapcar ;;; (alternatives (mapcar
(lambda (pair) ;;; (lambda (pair)
(cons ;;; (cons
(cdr pair) ;;; (cdr pair)
(car pair))) ;;; (car pair)))
(lyskom-get-strings lyskom-commands ;;; (lyskom-get-strings lyskom-commands
'lyskom-command))) ;;; 'lyskom-command)))
(name nil) (name nil)
(prefix-text (prefix-text
(cond ((eq prefix-arg '-) "- ") (cond ((eq prefix-arg '-) "- ")
((equal prefix-arg '(4)) "C-u ") ((equal prefix-arg '(4)) "C-u ")
((integerp prefix-arg) ((integerp prefix-arg)
(format "%d " prefix-arg)) (format "%d " prefix-arg))
((and (consp prefix-arg) ((and (consp prefix-arg)
(integerp (car prefix-arg))) (integerp (car prefix-arg)))
(format "%d " (car prefix-arg))) (format "%d " (car prefix-arg)))
(t nil))) (t nil)))
(prompt (if prefix-text (prompt (if prefix-text
(concat prefix-text (lyskom-get-string 'extended-command)) (concat prefix-text (lyskom-get-string 'extended-command))
(lyskom-get-string 'extended-command)))) (lyskom-get-string 'extended-command))))
(lyskom-with-lyskom-minibuffer (lyskom-with-lyskom-minibuffer
(setq name (lyskom-completing-read prompt (setq name (lyskom-completing-read prompt
(lyskom-maybe-frob-completion-table 'lyskom-complete-command
alternatives) (lambda (alt)
;; lyskom-is-administrator is buffer-local and (lyskom-ok-command alt
;; must be evalled before the call to lyskom-is-administrator))
;; completing-read t nil 'lyskom-command-history))
;; Yes, this is not beautiful (lyskom-lookup-command-by-name name (lambda (alt)
(list 'lambda '(alternative) (lyskom-ok-command
(list 'lyskom-ok-command 'alternative alt lyskom-is-administrator))))))
lyskom-is-administrator))
t nil 'lyskom-command-history)))
(cdr (lyskom-string-assoc name alternatives))))
(defun lyskom-update-command-completion () (defun lyskom-update-command-completion ()
"Build a list of alternatives for completion of LysKOM commands. "Build a list of alternatives for completion of LysKOM commands.
FIXME: Do this only when changing the language or logging in." Each list element is a vector [NAME COMMAND CANONICAL]. NAME is the
command name, COMMAND is the command and CANONICAL is the name
transformed for matching."
(setq lyskom-command-alternatives (setq lyskom-command-alternatives
(mapcar (lambda (el) (mapcar (lambda (el)
(vector (cdr el) (vector (cdr el)
...@@ -260,19 +258,23 @@ FIXME: Do this only when changing the language or logging in." ...@@ -260,19 +258,23 @@ FIXME: Do this only when changing the language or logging in."
(defun lyskom-complete-command (string predicate all) (defun lyskom-complete-command (string predicate all)
"Completion function for LysKOM commands." "Completion function for LysKOM commands."
(let ((alternatives nil) (let ((alternatives nil)
(string (lyskom-completing-match-string-regexp string))) (m-string (lyskom-completing-match-string-regexp string))
(exact nil))
(lyskom-traverse el lyskom-command-alternatives (lyskom-traverse el lyskom-command-alternatives
(when (and (string-match string (elt el 2)) (when (and (string-match m-string (elt el 2))
(or (null predicate) (funcall predicate el))) (or (null predicate) (funcall predicate el)))
(setq alternatives (cons (if (eq all 'lyskom-lookup) el (elt el 0)) (setq alternatives (cons (if (eq all 'lyskom-lookup) el (elt el 0)) alternatives))
alternatives)))) (if (eq (match-end 0) (length (elt el 2))) (setq exact t))))
(cond (cond
((eq all 'lyskom-lookup) (elt (car alternatives) 1)) ((eq all 'lyskom-lookup) (elt (car alternatives) 1))
((eq all 'lambda) (= (length alternatives) 1)) ((eq all 'lambda) (or (= (length alternatives) 1) exact))
(all alternatives) (all alternatives)
((null alternatives) nil) ((null alternatives) nil)
((eq (length alternatives) 1) t) ((= (length alternatives) 1)
(t (lyskom-complete-string alternatives))))) (if (string-equal string (lyskom-maybe-recode-string (car alternatives)))
t (lyskom-maybe-recode-string (car alternatives))))
(t (lyskom-maybe-recode-string
(lyskom-complete-string alternatives))))))
......
...@@ -2432,7 +2432,7 @@ The variable kom-keep-alive-interval controls the frequency of the request." ...@@ -2432,7 +2432,7 @@ The variable kom-keep-alive-interval controls the frequency of the request."
(or conf-no (or conf-no
(lyskom-read-conf-no (lyskom-get-string 'conf-to-check-mship-of) (lyskom-read-conf-no (lyskom-get-string 'conf-to-check-mship-of)
'(all) nil nil t)))) '(all) nil nil t))))
(if (lyskom-is-member pers-no conf-no) (if (lyskom-is-member conf-no pers-no)
(lyskom-format-insert 'pers-is-member-of-conf pers-no conf-no) (lyskom-format-insert 'pers-is-member-of-conf pers-no conf-no)
(lyskom-format-insert 'pers-is-not-member-of-conf pers-no conf-no)))) (lyskom-format-insert 'pers-is-not-member-of-conf pers-no conf-no))))
...@@ -443,6 +443,10 @@ then this returns nil. Otherwise, it returns an index into the buffer ...@@ -443,6 +443,10 @@ then this returns nil. Otherwise, it returns an index into the buffer
visible in the event's window." visible in the event's window."
(car (cdr (event-start e)))) (car (cdr (event-start e))))
(lyskom-provide-function event-closest-point (e)
"Return the character position closest to the mouse event EVENT."
(car (cdr (event-start e))))
(lyskom-provide-function event-glyph (e)) (lyskom-provide-function event-glyph (e))
......
...@@ -42,10 +42,20 @@ ...@@ -42,10 +42,20 @@
"Mode map for the `slow' lyskom command mode.") "Mode map for the `slow' lyskom command mode.")
(define-key lyskom-slow-mode-map (kbd "RET") 'kom-parse-command-and-execute) (define-key lyskom-slow-mode-map (kbd "RET") 'kom-parse-command-and-execute)
(define-key lyskom-slow-mode-map (kbd "TAB") 'kom-expand-slow-command)
(define-key lyskom-slow-mode-map (kbd "SPC") 'kom-expand-slow-or-next-command) (define-key lyskom-slow-mode-map (kbd "SPC") 'kom-expand-slow-or-next-command)
(define-key lyskom-slow-mode-map (kbd "C-a") 'kom-slow-start-of-line) (define-key lyskom-slow-mode-map (kbd "C-a") 'kom-slow-start-of-line)
(define-key lyskom-slow-mode-map (kbd "?") 'kom-slow-list-completions) (define-key lyskom-slow-mode-map (kbd "?") 'kom-slow-list-completions)
(define-key lyskom-slow-mode-map (kbd "*") 'kom-slow-button-press)
(define-key lyskom-slow-mode-map (kbd "=") 'kom-slow-menu-button-press)
(define-key lyskom-slow-mode-map (kbd "TAB") 'kom-expand-slow-command-or-next-link)
(define-key lyskom-slow-mode-map (kbd "M-TAB") 'kom-previous-link)
(define-key lyskom-slow-mode-map (kbd "C-i") 'kom-expand-slow-command-or-next-link)
(define-key lyskom-slow-mode-map (kbd "M-C-i") 'kom-previous-link)
(define-key lyskom-slow-mode-map (kbd (lyskom-keys 'button2)) 'kom-slow-click-or-yank)
(define-key lyskom-slow-mode-map (kbd (lyskom-keys 'button2up)) 'kom-mouse-null)
(define-key lyskom-slow-mode-map (kbd (lyskom-keys 'button3)) 'kom-popup-menu)
(define-key lyskom-slow-mode-map (kbd (lyskom-keys 'button3up)) 'kom-mouse-null)
(defun lyskom-slow-start-of-line () (defun lyskom-slow-start-of-line ()
"Move point to start of command, after LysKOM prompt." "Move point to start of command, after LysKOM prompt."
...@@ -72,9 +82,42 @@ If no text is entered, nil is returned." ...@@ -72,9 +82,42 @@ If no text is entered, nil is returned."
nil nil
(buffer-substring (point) (point-max)))) (buffer-substring (point) (point-max))))
(defun lyskom-slow-on-prompt-line (&optional where)
"Return non-nil if point is on the line containing the prompt.
Currently the prompt is assumed to be on the last line of the buffer."
(eq (save-excursion (when where (goto-char where)) (beginning-of-line) (point))
(save-excursion (goto-char (point-max)) (beginning-of-line) (point))))
(defun kom-slow-click-or-yank (event)
"Click on a LysKOM button or do the default action if after the prompt."
(interactive "@e")
(let ((pos (event-closest-point event)))
(if (and (lyskom-slow-on-prompt-line pos)
(<= (save-excursion (lyskom-slow-start-of-line) pos)))
(let ((fn (lookup-key global-map (this-command-keys))))
(when (commandp fn) (call-interactively fn)))
(kom-button-click event))))
(defun kom-slow-button-press ()
"Run kom-button-press unless on the prompt line."
(interactive)
(if (lyskom-slow-on-prompt-line)
(call-interactively 'self-insert-command)
(kom-button-press)))
(defun kom-slow-menu-button-press ()
"Run kom-menu-button-press unless on the prompt line."
(interactive)
(if (lyskom-slow-on-prompt-line)
(call-interactively 'self-insert-command)
(kom-menu-button-press)))
(defun kom-slow-start-of-line () (defun kom-slow-start-of-line ()
"Move to the beginning of line or start of command if on the prompt line."
(interactive) (interactive)
(lyskom-slow-start-of-line)) (if (lyskom-slow-on-prompt-line)
(lyskom-slow-start-of-line)
(beginning-of-line)))
(defun lyskom-expand-slow-command (try-exact eager-completion) (defun lyskom-expand-slow-command (try-exact eager-completion)
(let* ((saved-point (point-marker)) (let* ((saved-point (point-marker))
...@@ -125,6 +168,14 @@ If no text is entered, nil is returned." ...@@ -125,6 +168,14 @@ If no text is entered, nil is returned."
(t (signal 'lyskom-internal-error '())))))) (t (signal 'lyskom-internal-error '()))))))
command)) command))
(defun kom-expand-slow-command-or-next-link ()
"If on the prompt line, run kom-expand-slow-command.
Otherwise run kom-next-link."
(interactive)
(if (lyskom-slow-on-prompt-line)
(call-interactively 'kom-expand-slow-command)
(call-interactively 'kom-next-link)))
(defun kom-expand-slow-command (&optional try-exact) (defun kom-expand-slow-command (&optional try-exact)
"Tries to complete the command at point. "Tries to complete the command at point.
If optional TRY-EXACT is non-nil, look for an exact match. If optional TRY-EXACT is non-nil, look for an exact match.
......
...@@ -690,7 +690,7 @@ M ...@@ -690,7 +690,7 @@ M
(not-logged-in . "Du r inte inloggad. ") (not-logged-in . "Du r inte inloggad. ")
;; Used for kom-is-person-member-of-conference: ;; Used for kom-is-person-member-of-conference:
(pers-to-check-mship-for . "Vem vars medlemskap vill du underska? ") ;-) (pers-to-check-mship-for . "Vems medlemskap vill du underska? ") ;-)
(conf-to-check-mship-of . "...i vilket mte? ") (conf-to-check-mship-of . "...i vilket mte? ")
(conf-is-empty . "Mtet %#1M r tomt.\n") (conf-is-empty . "Mtet %#1M r tomt.\n")
(pers-is-member-of-conf . "Ja, %#1P r medlem i mtet %#2M.\n") (pers-is-member-of-conf . "Ja, %#1P r medlem i mtet %#2M.\n")
......
...@@ -1037,7 +1037,8 @@ at random and used. This element may be a string, function or list." ...@@ -1037,7 +1037,8 @@ at random and used. This element may be a string, function or list."
(def-kom-var lyskom-command-alternatives nil (def-kom-var lyskom-command-alternatives nil
"Possible command completions." "Possible command completions."
local) local
minibuffer)
(def-kom-var kom-trim-buffer-minimum 4096 (def-kom-var kom-trim-buffer-minimum 4096
"*This number of bytes rounded to a whole line is the amount of text trimmed "*This number of bytes rounded to a whole line is the amount of text trimmed
...@@ -2052,7 +2053,8 @@ an unknown person.") ...@@ -2052,7 +2053,8 @@ an unknown person.")
(def-kom-var lyskom-is-administrator nil (def-kom-var lyskom-is-administrator nil
"This variable is t if the user is in administrator mode and nil otherwise." "This variable is t if the user is in administrator mode and nil otherwise."
local) local
minibuffer)
(def-kom-var lyskom-last-personal-message-sender "" (def-kom-var lyskom-last-personal-message-sender ""
"Name of sender of last personal message received" "Name of sender of last personal message received"
......
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