I define an alist like this:
(setq major-mode-list
'(((emacs-lisp-mode inferior-emacs-lisp-mode) . ("Elisp" "Emacs"))
((haskell-mode) . ("Haskell" "Haskell"))
))
And match current major-mode with this function:
(defun major-mode-icon-3 ()
(let* ((match (assoc
(car (mapcar
(lambda (element)
(member (buffer-local-value 'major-mode (current-buffer))
element))
(map-keys major-mode-list)))
major-mode-list))
(name (car (cdr match)))
(icon (car (cdr (cdr match)))))
)
)
Function works correct in ((emacs-lisp-mode inferior-emacs-lisp-mode) . ("Elisp" "Emacs"))
.
But not correct in ((haskell-mode) . ("Haskell" "Haskell"))
. The function will
return nil
because of (car (haskell-mode))
.
Question: How to correct this function?
edebug
(evaluate thedefun
usingC-u C-M-x
instead ofC-M-x
). This will let you step through the function and evaluate individual expressions. – sds Oct 2 '16 at 16:01(buffer-local-value 'major-mode (current-buffer))
is redundant, just usemajor-mode
instead. – wasamasa Oct 2 '16 at 16:27assoc
on the result of themember
call of the first element of the key-list. – politza Oct 2 '16 at 19:54cl-assoc-if
. – npostavs Nov 2 '16 at 18:03