diff options
| author | Stefan Monnier | 2018-03-14 20:06:47 -0400 |
|---|---|---|
| committer | Thomas Fitzsimmons | 2018-04-15 19:24:15 -0400 |
| commit | 836dce63c3274eaa84a26c09a5b6dcb1522dba98 (patch) | |
| tree | 418199154ab997c7ec61168e84c3db4be2d58c5e | |
| parent | 7d0fa6081e7e307055b5dc47566061c0682e3ab7 (diff) | |
| download | emacs-836dce63c3274eaa84a26c09a5b6dcb1522dba98.tar.gz emacs-836dce63c3274eaa84a26c09a5b6dcb1522dba98.zip | |
EUDC: Enable lexical binding and do some cleanups
* lisp/net/eudc.el: Enable lexical binding.
(cl-lib): Always require cl-lib, not only when byte compiling.
(eudc-mode-map): Set parent keymap within let form.
(eudc-update-local-variables): Use #' read syntax for function
argument to map function.
(eudc-select): Likewise.
(eudc-format-attribute-name-for-display): Likewise
(eudc-filter-duplicate-attributes): Likewise.
(eudc-format-query): Likewise.
(eudc-expand-inline): Likewise.
(eudc-query-form): Likewise.
(eudc-print-attribute-value): Use mapc instead of mapcar.
(eudc-filter-partial-records): Use cl-every.
(eudc-distribute-field-on-records): Use delete-dups to
simplify function.
(eudc-expand-inline): Replace while with dolist and let form.
(eudc-query-form): Set inhibit-read-only after switching
buffers. Remove useless and call.
(eudc-load-eudc): Add a FIXME comment.
| -rw-r--r-- | lisp/net/eudc.el | 104 |
1 files changed, 45 insertions, 59 deletions
diff --git a/lisp/net/eudc.el b/lisp/net/eudc.el index 8d1071af727..98f70bd1f7a 100644 --- a/lisp/net/eudc.el +++ b/lisp/net/eudc.el | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | ;;; eudc.el --- Emacs Unified Directory Client | 1 | ;;; eudc.el --- Emacs Unified Directory Client -*- lexical-binding:t -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1998-2018 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1998-2018 Free Software Foundation, Inc. |
| 4 | 4 | ||
| @@ -47,7 +47,7 @@ | |||
| 47 | 47 | ||
| 48 | (require 'wid-edit) | 48 | (require 'wid-edit) |
| 49 | 49 | ||
| 50 | (eval-when-compile (require 'cl-lib)) | 50 | (require 'cl-lib) |
| 51 | 51 | ||
| 52 | (eval-and-compile | 52 | (eval-and-compile |
| 53 | (if (not (fboundp 'make-overlay)) | 53 | (if (not (fboundp 'make-overlay)) |
| @@ -68,6 +68,7 @@ | |||
| 68 | 68 | ||
| 69 | (defvar eudc-mode-map | 69 | (defvar eudc-mode-map |
| 70 | (let ((map (make-sparse-keymap))) | 70 | (let ((map (make-sparse-keymap))) |
| 71 | (set-keymap-parent map widget-keymap) | ||
| 71 | (define-key map "q" 'kill-current-buffer) | 72 | (define-key map "q" 'kill-current-buffer) |
| 72 | (define-key map "x" 'kill-current-buffer) | 73 | (define-key map "x" 'kill-current-buffer) |
| 73 | (define-key map "f" 'eudc-query-form) | 74 | (define-key map "f" 'eudc-query-form) |
| @@ -75,7 +76,6 @@ | |||
| 75 | (define-key map "n" 'eudc-move-to-next-record) | 76 | (define-key map "n" 'eudc-move-to-next-record) |
| 76 | (define-key map "p" 'eudc-move-to-previous-record) | 77 | (define-key map "p" 'eudc-move-to-previous-record) |
| 77 | map)) | 78 | map)) |
| 78 | (set-keymap-parent eudc-mode-map widget-keymap) | ||
| 79 | 79 | ||
| 80 | (defvar mode-popup-menu) | 80 | (defvar mode-popup-menu) |
| 81 | 81 | ||
| @@ -314,7 +314,7 @@ accordingly. Otherwise it is set to its EUDC default binding" | |||
| 314 | (defun eudc-update-local-variables () | 314 | (defun eudc-update-local-variables () |
| 315 | "Update all EUDC variables according to their local settings." | 315 | "Update all EUDC variables according to their local settings." |
| 316 | (interactive) | 316 | (interactive) |
| 317 | (mapcar 'eudc-update-variable eudc-local-vars)) | 317 | (mapcar #'eudc-update-variable eudc-local-vars)) |
| 318 | 318 | ||
| 319 | (eudc-default-set 'eudc-query-function nil) | 319 | (eudc-default-set 'eudc-query-function nil) |
| 320 | (eudc-default-set 'eudc-list-attributes-function nil) | 320 | (eudc-default-set 'eudc-list-attributes-function nil) |
| @@ -378,7 +378,7 @@ BEG and END delimit the text which is to be replaced." | |||
| 378 | (let ((replacement)) | 378 | (let ((replacement)) |
| 379 | (setq replacement | 379 | (setq replacement |
| 380 | (completing-read "Multiple matches found; choose one: " | 380 | (completing-read "Multiple matches found; choose one: " |
| 381 | (mapcar 'list choices))) | 381 | (mapcar #'list choices))) |
| 382 | (delete-region beg end) | 382 | (delete-region beg end) |
| 383 | (insert replacement))) | 383 | (insert replacement))) |
| 384 | 384 | ||
| @@ -415,7 +415,7 @@ underscore characters are replaced by spaces." | |||
| 415 | (if match | 415 | (if match |
| 416 | (cdr match) | 416 | (cdr match) |
| 417 | (capitalize | 417 | (capitalize |
| 418 | (mapconcat 'identity | 418 | (mapconcat #'identity |
| 419 | (split-string (symbol-name attribute) "_") | 419 | (split-string (symbol-name attribute) "_") |
| 420 | " "))))) | 420 | " "))))) |
| 421 | 421 | ||
| @@ -432,7 +432,7 @@ if any, is called to print the value in cdr of FIELD." | |||
| 432 | (progn | 432 | (progn |
| 433 | (eval (list (cdr match) val)) | 433 | (eval (list (cdr match) val)) |
| 434 | (insert "\n")) | 434 | (insert "\n")) |
| 435 | (mapcar | 435 | (mapc |
| 436 | (function | 436 | (function |
| 437 | (lambda (val-elem) | 437 | (lambda (val-elem) |
| 438 | (indent-to col) | 438 | (indent-to col) |
| @@ -598,9 +598,10 @@ otherwise they are formatted according to `eudc-user-attribute-names-alist'." | |||
| 598 | (setq result | 598 | (setq result |
| 599 | (eudc-add-field-to-records (cons (car field) | 599 | (eudc-add-field-to-records (cons (car field) |
| 600 | (mapconcat | 600 | (mapconcat |
| 601 | 'identity | 601 | #'identity |
| 602 | (cdr field) | 602 | (cdr field) |
| 603 | "\n")) result))) | 603 | "\n")) |
| 604 | result))) | ||
| 604 | ((eq 'duplicate method) | 605 | ((eq 'duplicate method) |
| 605 | (setq result | 606 | (setq result |
| 606 | (eudc-distribute-field-on-records field result))))))) | 607 | (eudc-distribute-field-on-records field result))))))) |
| @@ -613,12 +614,9 @@ otherwise they are formatted according to `eudc-user-attribute-names-alist'." | |||
| 613 | (mapcar | 614 | (mapcar |
| 614 | (function | 615 | (function |
| 615 | (lambda (rec) | 616 | (lambda (rec) |
| 616 | (if (eval (cons 'and | 617 | (if (cl-every (lambda (attr) |
| 617 | (mapcar | 618 | (consp (assq attr rec))) |
| 618 | (function | 619 | attrs) |
| 619 | (lambda (attr) | ||
| 620 | (consp (assq attr rec)))) | ||
| 621 | attrs))) | ||
| 622 | rec))) | 620 | rec))) |
| 623 | records))) | 621 | records))) |
| 624 | 622 | ||
| @@ -632,25 +630,14 @@ otherwise they are formatted according to `eudc-user-attribute-names-alist'." | |||
| 632 | (defun eudc-distribute-field-on-records (field records) | 630 | (defun eudc-distribute-field-on-records (field records) |
| 633 | "Duplicate each individual record in RECORDS according to value of FIELD. | 631 | "Duplicate each individual record in RECORDS according to value of FIELD. |
| 634 | Each copy is added a new field containing one of the values of FIELD." | 632 | Each copy is added a new field containing one of the values of FIELD." |
| 635 | (let (result | 633 | (let (result) |
| 636 | (values (cdr field))) | 634 | (dolist (value (delete-dups (cdr field))) ;; Uniquify values first. |
| 637 | ;; Uniquify values first | 635 | (setq result (nconc (eudc-add-field-to-records |
| 638 | (while values | 636 | (cons (car field) value) |
| 639 | (setcdr values (delete (car values) (cdr values))) | 637 | records) |
| 640 | (setq values (cdr values))) | 638 | result))) |
| 641 | (mapc | ||
| 642 | (function | ||
| 643 | (lambda (value) | ||
| 644 | (let ((result-list (copy-sequence records))) | ||
| 645 | (setq result-list (eudc-add-field-to-records | ||
| 646 | (cons (car field) value) | ||
| 647 | result-list)) | ||
| 648 | (setq result (append result-list result)) | ||
| 649 | ))) | ||
| 650 | (cdr field)) | ||
| 651 | result)) | 639 | result)) |
| 652 | 640 | ||
| 653 | |||
| 654 | (define-derived-mode eudc-mode special-mode "EUDC" | 641 | (define-derived-mode eudc-mode special-mode "EUDC" |
| 655 | "Major mode used in buffers displaying the results of directory queries. | 642 | "Major mode used in buffers displaying the results of directory queries. |
| 656 | There is no sense in calling this command from a buffer other than | 643 | There is no sense in calling this command from a buffer other than |
| @@ -776,8 +763,8 @@ otherwise a list of symbols is returned." | |||
| 776 | (setq query-alist (cdr query-alist))) | 763 | (setq query-alist (cdr query-alist))) |
| 777 | query) | 764 | query) |
| 778 | (if eudc-protocol-has-default-query-attributes | 765 | (if eudc-protocol-has-default-query-attributes |
| 779 | (mapconcat 'identity words " ") | 766 | (mapconcat #'identity words " ") |
| 780 | (list (cons 'name (mapconcat 'identity words " "))))))) | 767 | (list (cons 'name (mapconcat #'identity words " "))))))) |
| 781 | 768 | ||
| 782 | (defun eudc-extract-n-word-formats (format-list n) | 769 | (defun eudc-extract-n-word-formats (format-list n) |
| 783 | "Extract a list of N-long formats from FORMAT-LIST. | 770 | "Extract a list of N-long formats from FORMAT-LIST. |
| @@ -836,7 +823,6 @@ see `eudc-inline-expansion-servers'" | |||
| 836 | "[ \t]+")) | 823 | "[ \t]+")) |
| 837 | query-formats | 824 | query-formats |
| 838 | response | 825 | response |
| 839 | response-string | ||
| 840 | response-strings | 826 | response-strings |
| 841 | (eudc-former-server eudc-server) | 827 | (eudc-former-server eudc-server) |
| 842 | (eudc-former-protocol eudc-protocol) | 828 | (eudc-former-protocol eudc-protocol) |
| @@ -894,20 +880,18 @@ see `eudc-inline-expansion-servers'" | |||
| 894 | (error "No match") | 880 | (error "No match") |
| 895 | 881 | ||
| 896 | ;; Process response through eudc-inline-expansion-format | 882 | ;; Process response through eudc-inline-expansion-format |
| 897 | (while response | 883 | (dolist (r response) |
| 898 | (setq response-string | 884 | (let ((response-string |
| 899 | (apply 'format | 885 | (apply #'format |
| 900 | (car eudc-inline-expansion-format) | 886 | (car eudc-inline-expansion-format) |
| 901 | (mapcar (function | 887 | (mapcar (function |
| 902 | (lambda (field) | 888 | (lambda (field) |
| 903 | (or (cdr (assq field (car response))) | 889 | (or (cdr (assq field r)) |
| 904 | ""))) | 890 | ""))) |
| 905 | (eudc-translate-attribute-list | 891 | (eudc-translate-attribute-list |
| 906 | (cdr eudc-inline-expansion-format))))) | 892 | (cdr eudc-inline-expansion-format)))))) |
| 907 | (if (> (length response-string) 0) | 893 | (if (> (length response-string) 0) |
| 908 | (setq response-strings | 894 | (push response-string response-strings)))) |
| 909 | (cons response-string response-strings))) | ||
| 910 | (setq response (cdr response))) | ||
| 911 | 895 | ||
| 912 | (if (or | 896 | (if (or |
| 913 | (and replace (not eudc-expansion-overwrites-query)) | 897 | (and replace (not eudc-expansion-overwrites-query)) |
| @@ -923,7 +907,7 @@ see `eudc-inline-expansion-servers'" | |||
| 923 | (eudc-select response-strings beg end)) | 907 | (eudc-select response-strings beg end)) |
| 924 | ((eq eudc-multiple-match-handling-method 'all) | 908 | ((eq eudc-multiple-match-handling-method 'all) |
| 925 | (delete-region beg end) | 909 | (delete-region beg end) |
| 926 | (insert (mapconcat 'identity response-strings ", "))) | 910 | (insert (mapconcat #'identity response-strings ", "))) |
| 927 | ((eq eudc-multiple-match-handling-method 'abort) | 911 | ((eq eudc-multiple-match-handling-method 'abort) |
| 928 | (error "There is more than one match for the query"))))) | 912 | (error "There is more than one match for the query"))))) |
| 929 | (or (and (equal eudc-server eudc-former-server) | 913 | (or (and (equal eudc-server eudc-former-server) |
| @@ -943,10 +927,9 @@ queries the server for the existing fields and displays a corresponding form." | |||
| 943 | prompts | 927 | prompts |
| 944 | widget | 928 | widget |
| 945 | (width 0) | 929 | (width 0) |
| 946 | inhibit-read-only | ||
| 947 | pt) | 930 | pt) |
| 948 | (switch-to-buffer buffer) | 931 | (switch-to-buffer buffer) |
| 949 | (setq inhibit-read-only t) | 932 | (let ((inhibit-read-only t)) |
| 950 | (erase-buffer) | 933 | (erase-buffer) |
| 951 | (kill-all-local-variables) | 934 | (kill-all-local-variables) |
| 952 | (make-local-variable 'eudc-form-widget-list) | 935 | (make-local-variable 'eudc-form-widget-list) |
| @@ -960,11 +943,10 @@ queries the server for the existing fields and displays a corresponding form." | |||
| 960 | (widget-insert "Protocol : " (symbol-name eudc-protocol) "\n") | 943 | (widget-insert "Protocol : " (symbol-name eudc-protocol) "\n") |
| 961 | ;; Build the list of prompts | 944 | ;; Build the list of prompts |
| 962 | (setq prompts (if eudc-use-raw-directory-names | 945 | (setq prompts (if eudc-use-raw-directory-names |
| 963 | (mapcar 'symbol-name (eudc-translate-attribute-list fields)) | 946 | (mapcar #'symbol-name (eudc-translate-attribute-list fields)) |
| 964 | (mapcar (function | 947 | (mapcar (function |
| 965 | (lambda (field) | 948 | (lambda (field) |
| 966 | (or (and (assq field eudc-user-attribute-names-alist) | 949 | (or (cdr (assq field eudc-user-attribute-names-alist)) |
| 967 | (cdr (assq field eudc-user-attribute-names-alist))) | ||
| 968 | (capitalize (symbol-name field))))) | 950 | (capitalize (symbol-name field))))) |
| 969 | fields))) | 951 | fields))) |
| 970 | ;; Loop over prompt strings to find the longest one | 952 | ;; Loop over prompt strings to find the longest one |
| @@ -1008,7 +990,7 @@ queries the server for the existing fields and displays a corresponding form." | |||
| 1008 | "Quit") | 990 | "Quit") |
| 1009 | (goto-char pt) | 991 | (goto-char pt) |
| 1010 | (use-local-map widget-keymap) | 992 | (use-local-map widget-keymap) |
| 1011 | (widget-setup)) | 993 | (widget-setup))) |
| 1012 | ) | 994 | ) |
| 1013 | 995 | ||
| 1014 | (defun eudc-bookmark-server (server protocol) | 996 | (defun eudc-bookmark-server (server protocol) |
| @@ -1207,25 +1189,29 @@ queries the server for the existing fields and displays a corresponding form." | |||
| 1207 | 1189 | ||
| 1208 | ;;; Load time initializations : | 1190 | ;;; Load time initializations : |
| 1209 | 1191 | ||
| 1210 | ;;; Load the options file | 1192 | ;; Load the options file |
| 1211 | (if (and (not noninteractive) | 1193 | (if (and (not noninteractive) |
| 1212 | (and (locate-library eudc-options-file) | 1194 | (and (locate-library eudc-options-file) |
| 1213 | (progn (message "") t)) ; Remove mode line message | 1195 | (progn (message "") t)) ; Remove mode line message |
| 1214 | (not (featurep 'eudc-options-file))) | 1196 | (not (featurep 'eudc-options-file))) |
| 1215 | (load eudc-options-file)) | 1197 | (load eudc-options-file)) |
| 1216 | 1198 | ||
| 1217 | ;;; Install the full menu | 1199 | ;; Install the full menu |
| 1218 | (unless (featurep 'infodock) | 1200 | (unless (featurep 'infodock) |
| 1219 | (eudc-install-menu)) | 1201 | (eudc-install-menu)) |
| 1220 | 1202 | ||
| 1221 | 1203 | ||
| 1222 | ;;; The following installs a short menu for EUDC at XEmacs startup. | 1204 | ;; The following installs a short menu for EUDC at XEmacs startup. |
| 1223 | 1205 | ||
| 1224 | ;;;###autoload | 1206 | ;;;###autoload |
| 1225 | (defun eudc-load-eudc () | 1207 | (defun eudc-load-eudc () |
| 1226 | "Load the Emacs Unified Directory Client. | 1208 | "Load the Emacs Unified Directory Client. |
| 1227 | This does nothing except loading eudc by autoload side-effect." | 1209 | This does nothing except loading eudc by autoload side-effect." |
| 1228 | (interactive) | 1210 | (interactive) |
| 1211 | ;; FIXME: By convention, loading a file should "do nothing significant" | ||
| 1212 | ;; since Emacs may occasionally load a file for "frivolous" reasons | ||
| 1213 | ;; (e.g. to find a docstring), so having a function which just loads | ||
| 1214 | ;; the file doesn't seem very useful. | ||
| 1229 | nil) | 1215 | nil) |
| 1230 | 1216 | ||
| 1231 | ;;;###autoload | 1217 | ;;;###autoload |