Commit 336feb9e authored by Per Cederqvist's avatar Per Cederqvist
Browse files

kom-list-re performs a case insensitive match if a prefix argument is

parent f73178ba
2000-10-01 Per Cederqvist <ceder@moria>
* commands1.el (lyskom-make-re-case-insensitive): New function.
(kom-list-re): Be case insensitive if a prefix arg is given.
* (lyskom-char-classes): New variable.
* utilities.el (lyskom-default-collate-table): Doc-string
improved. Value fixed.
(lyskom-compute-char-classes): New function.
* startup.el (lyskom): Set lyskom-char-classes.
* lyskom-rest.el: Set a default value for lyskom-char-classes.
2000-09-15 David Byers <>
* command.el (lyskom-command-complete-word): Prevent multiple
......@@ -1630,10 +1630,78 @@ If you are not member in the conference it will be flagged with an asterisk."
;;; ================================================================
;;; Lista med regexpar - List regexp
(def-kom-command kom-list-re (regexp)
"List all persons and conferences whose name matches REGEXP."
(defun lyskom-make-re-case-insensitive (re)
"Convert the regexp RE to a case insensitive regexp."
(unless lyskom-char-classes
(setq lyskom-char-classes
(lyskom-compute-char-classes lyskom-collate-table)))
(let ((res nil)
(input (split-string re ""))
(while input
;; Copy "[]" character sets literally.
((string= (car input) "[")
(setq res (cons "[" res))
(setq input (cdr input))
(when input ;Handle "[]asdf]" properly.
(setq res (cons (car input) res))
(setq input (cdr input)))
(while (and input (not (string= (car input) "]")))
(setq res (cons (car input) res))
(setq input (cdr input)))
(when input ;Don't forget the terminating "]".
(setq res (cons (car input) res))
(setq input (cdr input))))
;; Copy backslashed sequences literally.
((string= (car input) "\\")
(setq res (cons "\\" res))
(setq input (cdr input))
(when input
(setq res (cons (car input) res))
(setq input (cdr input))))
;; Copy special characters literally.
((member (car input) '("(" ")" "|" "+" "*" "?"))
(setq res (cons (car input) res))
(setq input (cdr input)))
;; Create "[]" character sets for equivalent characters.
((setq val (cdr-safe (assoc (aref (car input) 0) lyskom-char-classes)))
(setq res (cons "[" res))
(if (member "]" val) ;"]" must come first.
(setq res (cons "]" res)))
(while val
((string= "]" (car val))) ;already handled
((string= "-" (car val))
(setq res (cons "---" res)))
(setq res (cons (car val) res))))
(setq val (cdr val)))
(setq res (cons "]" res))
(setq input (cdr input)))
;; Copy other characters literally.
(setq res (cons (car input) res))
(setq input (cdr input)))))
(apply 'concat (nreverse res))))
(def-kom-command kom-list-re (regexp &optional case-insensitive)
"List all persons and conferences whose name matches REGEXP.
If the optional argument CASE-INSENSITIVE is true, the regexp will be
converted so that the search is case insensitive."
(interactive (list (lyskom-read-string
(lyskom-get-string 'search-re))))
(lyskom-get-string 'search-re))
(if case-insensitive
(setq regexp (lyskom-make-re-case-insensitive regexp)))
(lyskom-format-insert 'matching-regexp regexp)
(let ((conf-list (blocking-do 're-z-lookup regexp 1 1)))
(if conf-list
......@@ -3555,6 +3555,11 @@ One parameter - the prompt string."
(setq-default lyskom-collate-table lyskom-default-collate-table)
;; We should set lyskom-char-classes to
;; (lyskom-compute-char-classes lyskom-collate-table))
;; but that currently fails under Emacs 20.7, because
;; lyskom-default-collate-table isn't set properly.
(setq-default lyskom-char-classes nil)
(lyskom-set-language lyskom-language)
(unless (or (memq 'lyskom-unread-mode-line global-mode-string)
(rassq 'lyskom-unread-mode-line global-mode-string))
......@@ -262,6 +262,7 @@ See lyskom-mode for details."
(when (lyskom-have-call 85)
(setq lyskom-collate-table (blocking-do 'get-collate-table))
(setq lyskom-char-classes nil)
(if (not (zerop (server-info->motd-of-lyskom
......@@ -835,6 +836,7 @@ to see, set of call."
(setq lyskom-do-when-done (cons kom-do-when-done kom-do-when-done))
(setq lyskom-output-queues (make-vector 10 nil))
(setq lyskom-collate-table lyskom-default-collate-table)
(setq lyskom-char-classes nil)
(let ((i 0))
(while (< i 10)
(aset lyskom-output-queues i (lyskom-queue-create))
......@@ -310,7 +310,11 @@ TYPE should be `list' or `vector'."
(defvar lyskom-default-collate-table
"\000\001\002\003\004\005\006\007\010 \012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]~\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237!AAAA[]ACEEEEIIIINOOOO\\OUUUYYAAAA[]ACEEEEIIIINOOOO\\OUUUYY"
"String mapping lowercase to uppercase and equivalents to each others.")
"String mapping characters to their collate class.
Lowercase, uppercase and other equivalents are mapped to the same class.
The class number defines a proper sorting order.")
(defsubst lyskom-maybe-recode-string (s &optional coding force)
"Change the encoding of S for when multibyte characters are not supported.
......@@ -377,6 +381,53 @@ is non-nil."
(error nil)))
(defun lyskom-compute-char-classes (map)
"Find out which characters that are equivalent according to MAP.
MAP should be a collate table.
The return value is an assoc list, which characters as keys, and a
list of single-character strings as values. Only characters that are
equivalent to at least one more character is returned in the assoc
Example: if this function returns
((97 \"A\" \"a\")
(65 \"A\" \"a\")
(48 \"O\" \"o\" \"0\")
(111 \"O\" \"o\" \"0\")
(79 \"O\" \"o\" \"0\"))
it means that a and A are equivalent, and o, O and 0 are equivalent.
All other characters are unique."
(and lyskom-buffer (set-buffer lyskom-buffer))
(let ((ix (length map))
(cls-to-strings nil)) ;assoc-list from equivalence class to
;list of chars
(while (> ix 0)
(setq ix (1- ix))
(let* ((cls (aref map ix))
(str (decode-coding-string (concat (vector ix))
(elem (assoc cls cls-to-strings)))
(if elem
(rplacd elem (cons str (cdr elem)))
(setq cls-to-strings (cons (list cls str) cls-to-strings)))))
(let ((res nil))
(while cls-to-strings
(let ((lst (cdar cls-to-strings)))
(if (> (length lst) 1)
(while lst
(setq res (cons (cons (string-to-char (car lst))
(cdar cls-to-strings))
(setq lst (cdr lst)))))
(setq cls-to-strings (cdr cls-to-strings)))
;; Stolen from thingatpt.el
;; FIXME: We may not really need this function. Check the callers.
......@@ -2086,7 +2086,12 @@ an unknown person.")
"Microseconds timeout for accept-process-output.")
(def-kom-var lyskom-collate-table nil
"Table mapping characters to equivalent characters."
"Table mapping characters to an equivalence class."
(def-kom-var lyskom-char-classes nil
"An assoc list from character to a list of equivalent strings.
See lyskom-compute-char-classes."
(def-kom-var lyskom-dont-read-user-area nil
Supports Markdown
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