Skip to content

Commit

Permalink
Use setf slot-value everywhere.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thierry Volpiatto committed Apr 8, 2016
1 parent 217d84f commit ca2f5bb
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 103 deletions.
13 changes: 6 additions & 7 deletions helm-files.el
Original file line number Diff line number Diff line change
Expand Up @@ -3032,13 +3032,12 @@ Don't use it in your own code unless you know what you are doing.")
(persistent-action :initform 'helm-ff-kill-or-find-buffer-fname)))

(defmethod helm--setup-source :after ((source helm-recentf-source))
(set-slot-value
source 'action
(append (symbol-value (helm-actions-from-type-file))
'(("Delete file(s) from recentf" .
(lambda (_candidate)
(cl-loop for file in (helm-marked-candidates)
do (setq recentf-list (delq file recentf-list)))))))))
(setf (slot-value source 'action)
(append (symbol-value (helm-actions-from-type-file))
'(("Delete file(s) from recentf" .
(lambda (_candidate)
(cl-loop for file in (helm-marked-candidates)
do (setq recentf-list (delq file recentf-list)))))))))

(defvar helm-source-recentf nil
"See (info \"(emacs)File Conveniences\").
Expand Down
8 changes: 4 additions & 4 deletions helm-org.el
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ Note this have no effect in `helm-org-in-buffer-headings'."

(defmethod helm--setup-source :after ((source helm-org-headings-class))
(let ((parents (slot-value source 'parents)))
(set-slot-value source 'candidate-transformer
(lambda (candidates)
(let ((cands (helm-org-get-candidates candidates parents)))
(if parents (nreverse cands) cands))))))
(setf (slot-value source 'candidate-transformer)
(lambda (candidates)
(let ((cands (helm-org-get-candidates candidates parents)))
(if parents (nreverse cands) cands))))))

(defun helm-source-org-headings-for-files (filenames &optional parents)
(helm-make-source "Org Headings" 'helm-org-headings-class
Expand Down
103 changes: 51 additions & 52 deletions helm-source.el
Original file line number Diff line number Diff line change
Expand Up @@ -759,14 +759,14 @@ Argument CLASS is an eieio class object.
Arguments ARGS are keyword value pairs as defined in CLASS."
(declare (indent 2))
(let ((source (apply #'make-instance class name args)))
(set-slot-value source 'name name)
(setf (slot-value source 'name) name)
(helm--setup-source source)
(helm-setup-user-source source)
(helm--create-source source)))

(defun helm-make-type (class &rest args)
(let ((source (apply #'make-instance class args)))
(set-slot-value source 'name nil)
(setf (slot-value source 'name) nil)
(helm--setup-source source)
(helm--create-source source)))

Expand Down Expand Up @@ -819,14 +819,12 @@ an eieio class."
actions (quote ,new-action) ,index))
(t actions)))))
(if (functionp actions)
(set-slot-value source 'action (list (cons "Default action" actions)))
(set-slot-value source 'action (helm-interpret-value actions source)))
(setf (slot-value source 'action) (list (cons "Default action" actions)))
(setf (slot-value source 'action) (helm-interpret-value actions source)))
(when (or (symbolp action-transformers) (functionp action-transformers))
(setq action-transformers (list action-transformers)))
(set-slot-value
source
'action-transformer
(delq nil (append (list transformer) action-transformers)))))
(setf (slot-value source 'action-transformer)
(delq nil (append (list transformer) action-transformers)))))


;;; Methods to build sources.
Expand Down Expand Up @@ -875,74 +873,75 @@ an eieio class."
(warn "Deprecated usage of helm `delayed' slot in `%s'"
(slot-value source 'name)))
(helm-aif (slot-value source 'keymap)
(and (symbolp it) (set-slot-value source 'keymap (symbol-value it))))
(and (symbolp it) (setf (slot-value source 'keymap) (symbol-value it))))
(helm-aif (slot-value source 'persistent-help)
(set-slot-value source 'header-line
(helm-source--persistent-help-string it source))
(set-slot-value source 'header-line (helm-source--header-line source)))
(setf (slot-value source 'header-line)
(helm-source--persistent-help-string it source))
(setf (slot-value source 'header-line) (helm-source--header-line source)))
(helm-aif (slot-value source 'candidate-number-limit)
(and (symbolp it) (set-slot-value
source 'candidate-number-limit (symbol-value it))))
(and (symbolp it) (setf (slot-value source 'candidate-number-limit)
(symbol-value it))))
(when (and (slot-value source 'fuzzy-match) helm-fuzzy-sort-fn)
(set-slot-value source 'filtered-candidate-transformer
(helm-aif (slot-value source 'filtered-candidate-transformer)
(append (helm-mklist it)
(list helm-fuzzy-sort-fn))
(list helm-fuzzy-sort-fn))))
(setf (slot-value source 'filtered-candidate-transformer)
(helm-aif (slot-value source 'filtered-candidate-transformer)
(append (helm-mklist it)
(list helm-fuzzy-sort-fn))
(list helm-fuzzy-sort-fn))))
(unless (slot-value source 'nohighlight)
(set-slot-value source 'filtered-candidate-transformer
(helm-aif (slot-value source 'filtered-candidate-transformer)
(append (helm-mklist it)
(list #'helm-fuzzy-highlight-matches))
(list #'helm-fuzzy-highlight-matches)))))
(setf (slot-value source 'filtered-candidate-transformer)
(helm-aif (slot-value source 'filtered-candidate-transformer)
(append (helm-mklist it)
(list #'helm-fuzzy-highlight-matches))
(list #'helm-fuzzy-highlight-matches)))))

(defmethod helm-setup-user-source ((_source helm-source)))

(defmethod helm--setup-source ((source helm-source-sync))
(when (slot-value source 'fuzzy-match)
(helm-aif (slot-value source 'match)
(set-slot-value source 'match (append (helm-mklist it)
(list helm-fuzzy-match-fn)))
(set-slot-value source 'match helm-fuzzy-match-fn)))
(setf (slot-value source 'match)
(append (helm-mklist it)
(list helm-fuzzy-match-fn)))
(setf (slot-value source 'match) helm-fuzzy-match-fn)))
(when (slot-value source 'matchplugin)
(set-slot-value source 'match
(helm-source-mm-get-search-or-match-fns source 'match)))
(setf (slot-value source 'match)
(helm-source-mm-get-search-or-match-fns source 'match)))
(helm-aif (and (null (slot-value source 'matchplugin))
(slot-value source 'migemo))
(unless (eq it 'nomultimatch) ; Use own migemo fn.
(set-slot-value source 'match
(append (helm-mklist (slot-value source 'match))
'(helm-mm-3-migemo-match))))))
(setf (slot-value source 'match)
(append (helm-mklist (slot-value source 'match))
'(helm-mm-3-migemo-match))))))

(defmethod helm--setup-source ((source helm-source-in-buffer))
(let ((cur-init (slot-value source 'init)))
(helm-aif (slot-value source 'data)
(set-slot-value
source
'init (delq
nil
(list
(and (null (eq 'helm-default-init-source-in-buffer-function
cur-init))
cur-init)
(lambda ()
(helm-init-candidates-in-buffer
'global
(if (functionp it) (funcall it) it))))))))
(setf (slot-value source 'init)
(delq
nil
(list
(and (null (eq 'helm-default-init-source-in-buffer-function
cur-init))
cur-init)
(lambda ()
(helm-init-candidates-in-buffer
'global
(if (functionp it) (funcall it) it))))))))
(when (slot-value source 'fuzzy-match)
(helm-aif (slot-value source 'search)
(set-slot-value source 'search (append (helm-mklist it)
(list helm-fuzzy-search-fn)))
(set-slot-value source 'search (list helm-fuzzy-search-fn))))
(setf (slot-value source 'search)
(append (helm-mklist it)
(list helm-fuzzy-search-fn)))
(setf (slot-value source 'search) (list helm-fuzzy-search-fn))))
(when (slot-value source 'matchplugin)
(set-slot-value
source 'search (helm-source-mm-get-search-or-match-fns source 'search)))
(setf (slot-value source 'search)
(helm-source-mm-get-search-or-match-fns source 'search)))
(helm-aif (and (null (slot-value source 'matchplugin))
(slot-value source 'migemo))
(unless (eq it 'nomultimatch)
(set-slot-value source 'search
(append (helm-mklist (slot-value source 'search))
'(helm-mm-3-migemo-search)))))
(setf (slot-value source 'search)
(append (helm-mklist (slot-value source 'search))
'(helm-mm-3-migemo-search)))))
(let ((mtc (slot-value source 'match)))
(cl-assert (or (equal '(identity) mtc)
(eq 'identity mtc))
Expand Down
78 changes: 39 additions & 39 deletions helm-types.el
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,19 @@
(defmethod helm--setup-source :primary ((_source helm-type-file)))

(defmethod helm--setup-source :before ((source helm-type-file))
(set-slot-value source 'action 'helm-type-file-actions)
(set-slot-value source 'persistent-help "Show this file")
(set-slot-value source 'action-transformer '(helm-transform-file-load-el
helm-transform-file-browse-url
helm-transform-file-cache))
(set-slot-value source 'candidate-transformer '(helm-skip-boring-files
helm-highlight-files
helm-w32-pathname-transformer))
(set-slot-value source 'help-message 'helm-generic-file-help-message)
(set-slot-value source 'mode-line (list "File(s)" helm-mode-line-string))
(set-slot-value source 'keymap helm-generic-files-map))
(setf (slot-value source 'action) 'helm-type-file-actions)
(setf (slot-value source 'persistent-help) "Show this file")
(setf (slot-value source 'action-transformer)
'(helm-transform-file-load-el
helm-transform-file-browse-url
helm-transform-file-cache))
(setf (slot-value source 'candidate-transformer)
'(helm-skip-boring-files
helm-highlight-files
helm-w32-pathname-transformer))
(setf (slot-value source 'help-message) 'helm-generic-file-help-message)
(setf (slot-value source 'mode-line) (list "File(s)" helm-mode-line-string))
(setf (slot-value source 'keymap) helm-generic-files-map))


;; Bookmarks
Expand Down Expand Up @@ -109,11 +111,11 @@
(defmethod helm--setup-source :primary ((_source helm-type-bookmark)))

(defmethod helm--setup-source :before ((source helm-type-bookmark))
(set-slot-value source 'action 'helm-type-bookmark-actions)
(set-slot-value source 'keymap helm-bookmark-map)
(set-slot-value source 'mode-line (list "Bookmark(s)" helm-mode-line-string))
(set-slot-value source 'help-message 'helm-bookmark-help-message)
(set-slot-value source 'migemo t))
(setf (slot-value source 'action) 'helm-type-bookmark-actions)
(setf (slot-value source 'keymap) helm-bookmark-map)
(setf (slot-value source 'mode-line) (list "Bookmark(s)" helm-mode-line-string))
(setf (slot-value source 'help-message) 'helm-bookmark-help-message)
(setf (slot-value source 'migemo) t))


;; Buffers
Expand Down Expand Up @@ -159,14 +161,13 @@
(defmethod helm--setup-source :primary ((_source helm-type-buffer)))

(defmethod helm--setup-source :before ((source helm-type-buffer))
(set-slot-value source 'action 'helm-type-buffer-actions)
(set-slot-value source 'persistent-help "Show this buffer")
(set-slot-value source 'mode-line (list "Buffer(s)" helm-mode-line-string))
(set-slot-value
source 'filtered-candidate-transformer
'(helm-skip-boring-buffers
helm-buffers-sort-transformer
helm-highlight-buffers)))
(setf (slot-value source 'action) 'helm-type-buffer-actions)
(setf (slot-value source 'persistent-help) "Show this buffer")
(setf (slot-value source 'mode-line) (list "Buffer(s)" helm-mode-line-string))
(setf (slot-value source 'filtered-candidate-transformer)
'(helm-skip-boring-buffers
helm-buffers-sort-transformer
helm-highlight-buffers)))

;; Functions
(defclass helm-type-function (helm-source) ()
Expand Down Expand Up @@ -197,12 +198,12 @@
(defmethod helm--setup-source :primary ((_source helm-type-function)))

(defmethod helm--setup-source :before ((source helm-type-function))
(set-slot-value source 'action 'helm-type-function-actions)
(set-slot-value source 'action-transformer
'helm-transform-function-call-interactively)
(set-slot-value source 'candidate-transformer
'helm-mark-interactive-functions)
(set-slot-value source 'coerce 'helm-symbolify))
(setf (slot-value source 'action) 'helm-type-function-actions)
(setf (slot-value source 'action-transformer)
'helm-transform-function-call-interactively)
(setf (slot-value source 'candidate-transformer)
'helm-mark-interactive-functions)
(setf (slot-value source 'coerce) 'helm-symbolify))


;; Commands
Expand All @@ -225,10 +226,9 @@
(defmethod helm--setup-source :primary ((_source helm-type-command)))

(defmethod helm--setup-source :before ((source helm-type-command))
(set-slot-value
source 'action 'helm-type-command-actions)
(set-slot-value source 'coerce 'helm-symbolify)
(set-slot-value source 'persistent-action 'describe-function))
(setf (slot-value source 'action) 'helm-type-command-actions)
(setf (slot-value source 'coerce) 'helm-symbolify)
(setf (slot-value source 'persistent-action) 'describe-function))

;; Timers
(defclass helm-type-timers (helm-source) ()
Expand All @@ -253,11 +253,11 @@
(defmethod helm--setup-source :primary ((_source helm-type-timers)))

(defmethod helm--setup-source :before ((source helm-type-timers))
(set-slot-value source 'action 'helm-type-timers-actions)
(set-slot-value source 'persistent-action
(lambda (tm)
(describe-function (timer--function tm))))
(set-slot-value source 'persistent-help "Describe Function"))
(setf (slot-value source 'action) 'helm-type-timers-actions)
(setf (slot-value source 'persistent-action)
(lambda (tm)
(describe-function (timer--function tm))))
(setf (slot-value source 'persistent-help) "Describe Function"))

;; Builders.
(defun helm-build-type-file ()
Expand Down
2 changes: 1 addition & 1 deletion helm.el
Original file line number Diff line number Diff line change
Expand Up @@ -5382,7 +5382,7 @@ If the source is defined with its own class,
you can use `helm-setup-user-source' e.g:

(defmethod helm-setup-user-source ((source helm-grep-class))
(set-slot-value source 'follow 1))
(setf (slot-value source 'follow) 1))

Otherwise, use `helm-attrset' to setup the `follow' attribute of the existing source,
which see.
Expand Down

0 comments on commit ca2f5bb

Please sign in to comment.