From: Björn Lindqvist Date: Tue, 6 Feb 2018 04:19:35 +0000 (+0100) Subject: FUEL: alist-get instead of (cdr (assoc key alist)) X-Git-Tag: 0.98~364 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=428023ad22615559a35c304da6284fca83a4825e FUEL: alist-get instead of (cdr (assoc key alist)) alist-get is a new function in emacs 25. It makes working with assocs a bit simpler. --- diff --git a/misc/fuel/fuel-base.el b/misc/fuel/fuel-base.el index 8044b11102..48d8026558 100644 --- a/misc/fuel/fuel-base.el +++ b/misc/fuel/fuel-base.el @@ -20,7 +20,6 @@ (interactive) (message "FUEL %s" fuel-version)) - ;;; Customization: ;;;###autoload @@ -28,9 +27,7 @@ "Factor's Ultimate Emacs Library." :group 'languages) - -;;; Utilities: - +;;; Compatibility with Emacs 24.3 (unless (fboundp 'setq-local) (defmacro setq-local (var val) (list 'set (list 'make-local-variable (list 'quote var)) val))) @@ -41,6 +38,11 @@ (list 'progn (list 'defvar var val docstring) (list 'make-variable-buffer-local (list 'quote var))))) +(unless (fboundp 'alist-get) + (defun alist-get (key alist) + (cdr (assoc key alist)))) + +;;; Utilities: (defun fuel-shorten-str (str len) (let ((sl (length str))) (if (<= sl len) str diff --git a/misc/fuel/fuel-connection.el b/misc/fuel/fuel-connection.el index cd5754cdec..87a6f63c51 100644 --- a/misc/fuel/fuel-connection.el +++ b/misc/fuel/fuel-connection.el @@ -1,5 +1,6 @@ ;;; fuel-connection.el -- asynchronous comms with the fuel listener +;; Copyright (C) 2018 Björn Lindqvist ;; Copyright (C) 2008, 2009 Jose Antonio Ortega Ruiz ;; See http://factorcode.org/license.txt for BSD license. @@ -48,23 +49,17 @@ (defsubst fuel-con--request-p (req) (and (listp req) (eq (car req) :fuel-connection-request))) -(defsubst fuel-con--request-id (req) - (cdr (assoc :id req))) - (defsubst fuel-con--request-string (req) - (cdr (assoc :string req))) - -(defsubst fuel-con--request-continuation (req) - (cdr (assoc :continuation req))) + (alist-get :string req)) (defsubst fuel-con--request-buffer (req) - (cdr (assoc :buffer req))) + (alist-get :buffer req)) (defsubst fuel-con--request-deactivate (req) (setcdr (assoc :continuation req) nil)) (defsubst fuel-con--request-deactivated-p (req) - (null (cdr (assoc :continuation req)))) + (null (alist-get :continuation req))) ;;; TODO Replace with a defstruct (defsubst fuel-con--make-connection (buffer) @@ -79,23 +74,23 @@ (and (listp c) (eq (car c) :fuel-connection))) (defsubst fuel-con--connection-requests (c) - (cdr (assoc :requests c))) + (alist-get :requests c)) (defsubst fuel-con--connection-current-request (c) - (cdr (assoc :current c))) + (alist-get :current c)) (defun fuel-con--connection-clean-current-request (c) (let* ((cell (assoc :current c)) (req (cdr cell))) (when req - (puthash (fuel-con--request-id req) req (cdr (assoc :completed c))) + (puthash (alist-get :id req) req (alist-get :completed c)) (setcdr cell nil)))) (defsubst fuel-con--connection-completed-p (c id) - (gethash id (cdr (assoc :completed c)))) + (gethash id (alist-get :completed c))) (defsubst fuel-con--connection-buffer (c) - (cdr (assoc :buffer c))) + (alist-get :buffer c)) (defun fuel-con--connection-pop-request (c) (let ((reqs (assoc :requests c)) @@ -210,16 +205,16 @@ sexp. fuel-con-error is thrown if the sexp is malformed." (fuel-con--connection-cancel-timer con) (when (and buffer req str) (set-buffer buffer) - (fuel-log--info "<%s>: %s" (fuel-con--request-id req) str) + (fuel-log--info "<%s>: %s" (alist-get :id req) str) (comint-redirect-send-command (format "%s" str) cbuf nil t)))))) (defun fuel-con--process-completed-request (req) - (let ((cont (fuel-con--request-continuation req)) - (id (fuel-con--request-id req)) + (let ((cont (alist-get :continuation req)) + (id (alist-get :id req)) (rstr (fuel-con--request-string req)) (buffer (fuel-con--request-buffer req))) (if (not cont) - (fuel-log--warn "<%s> Droping result for request %S (%s)" + (fuel-log--warn "<%s> Dropping result for request %S (%s)" id rstr req) (condition-case cerr (with-current-buffer (or buffer (current-buffer)) @@ -258,7 +253,7 @@ sexp. fuel-con-error is thrown if the sexp is malformed." (let ((con (fuel-con--get-connection buffer/proc))) (unless con (error fuel-con--error-message)) (let* ((req (fuel-con--send-string buffer/proc str cont sbuf)) - (id (and req (fuel-con--request-id req))) + (id (and req (alist-get :id req))) (time (or timeout fuel-connection-timeout)) (step 100) (waitsecs (/ step 1000.0))) diff --git a/misc/fuel/fuel-eval.el b/misc/fuel/fuel-eval.el index 10be5fd793..0e84e60ec8 100644 --- a/misc/fuel/fuel-eval.el +++ b/misc/fuel/fuel-eval.el @@ -144,8 +144,8 @@ (assoc name err)))) (defsubst fuel-eval--error-restarts (err) - (cdr (assoc :restarts (or (fuel-eval--error-name-p err 'condition) - (fuel-eval--error-name-p err 'lexer-error))))) + (alist-get :restarts (or (fuel-eval--error-name-p err 'condition) + (fuel-eval--error-name-p err 'lexer-error)))) (defsubst fuel-eval--error-file (err) (nth 1 (fuel-eval--error-name-p err 'source-file-error))) diff --git a/misc/fuel/fuel-markup.el b/misc/fuel/fuel-markup.el index 02fc73b041..7d10cd512f 100644 --- a/misc/fuel/fuel-markup.el +++ b/misc/fuel/fuel-markup.el @@ -182,10 +182,10 @@ ((stringp e) (fuel-markup--insert-string e)) ((and (listp e) (symbolp (car e)) (assoc (car e) fuel-markup--printers)) - (funcall (cdr (assoc (car e) fuel-markup--printers)) e)) + (funcall (alist-get (car e) fuel-markup--printers) e)) ((and (symbolp e) (assoc e fuel-markup--printers)) - (funcall (cdr (assoc e fuel-markup--printers)) e)) + (funcall (alist-get e fuel-markup--printers) e)) ((listp e) (mapc 'fuel-markup--print e)) ((symbolp e) (fuel-markup--print (list '$link e))) (t (insert (format "\n%S\n" e)))))