2

I've been looking around for a solution to get company-mode to auto-complete R library names in ess-mode. The R libraries are stored in folders with the same name, wouldn't it be just the case of picking candidates from a directory tree? Does anyone know how to make ess-mode auto-compelte library names?

Thanks.

1 Answer 1

1

I've been reading a bit about Emacs Lisp and came up with the following solution. This is my very first Lisp function and as such I am not sure whether I've covered all pitfalls. It requires running iESS.

;; insert R library line using helm
(defun helm-ess-R-library-name-insert ()
  "Insert 'library(_library-name_)'."
  (interactive)
  (let
      ((lib-name (helm :sources (helm-build-in-buffer-source "R-library"
                  :data (ess-get-words-from-vector
                     "print(.packages(T), max=1e6)\n"))
               :buffer "*R library*")))
    (if (not (string= lib-name nil))
       (if (string= (message "%s" major-mode) "ess-mode")
          (insert (format "library(%s)\n" lib-name))
         (ess-eval-linewise (format "library('%s')\n" lib-name))))))
;; re-map the key from ess-load-library
(define-key ess-mode-map (kbd "C-c C-e l") 'helm-ess-R-library-name-insert)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.