Is there a way to use Rmarkdown in Spacemacs? - emacs

I know that Emacs has the polymode package that allows coding in RMarkdown. However, it seems that Spacemacs is still missing the equivalent of a polymode layer.
I have been trying to install it directly into Spacemacs, with no success. Therefore my question: is there a way to edit RMarkdown files in Spacemacs (not plain Emacs).

you can add packages to spacemacs by adding them to dotspacemacs-additional-packages in your .spacemacs:
dotspacemacs-additional-packages '(polymode poly-R poly-noweb poly-markdown)
after a restart the packages should get installed automatically, you probably want to set some other options in dotspacemacs/user-config () e.g. something like:
(add-to-list 'auto-mode-alist '("\\.md" . poly-markdown-mode))
(add-to-list 'auto-mode-alist '("\\.Snw" . poly-noweb+r-mode))
(add-to-list 'auto-mode-alist '("\\.Rnw" . poly-noweb+r-mode))
(add-to-list 'auto-mode-alist '("\\.Rmd" . poly-markdown+r-mode))
Edit:
polymode got a rework.

There's no official polymode layer for Spacemacs, but I've found a couple of implementations in random configs on GitHub. Here's one that works for me:
;;; packages.el --- polymode layer packages file for Spacemacs.
;;
;; Copyright (c) 2012-2016 Sylvain Benner & Contributors
;;
;; Author: Walmes Zeviani & Fernando Mayer
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; Layer retrieved from here:
;; https://github.com/MilesMcBain/spacemacs_cfg/blob/master/private/polymode/packages.el
;;
;;; Code:
(defconst polymode-packages
'(polymode
poly-R
poly-markdown))
(defun polymode/init-poly-R ())
(defun polymode/init-poly-markdown ())
(defun polymode/init-polymode ()
(use-package polymode
:mode (("\\.Rmd" . Rmd-mode))
:init
(progn
(defun Rmd-mode ()
"ESS Markdown mode for Rmd files"
(interactive)
(require 'poly-R)
(require 'poly-markdown)
(R-mode)
(poly-markdown+r-mode))
))
)
;;; packages.el ends here
There are a few ways to work with private custom layers like this, but one straightforward and easy way is to...
Save the code above as a file named packages.el in ~/.emacs.d/layers/private/polymode/.
Add polymode to your list of dotspacemacs/layers, e.g.
(defun dotspacemacs/layers ()
ess
polymode
python
...
Restart Emacs and the polymode package should install.
Using this, you shouldn't have to use (add-to-list 'auto-mode-alist... to declare the particular mode that .Rmd files should use since it's defined in the layer. I retrieved this particular layer from here. I tried one or two others as well, but they didn't work for me.

Related

Setting up emacs on new machine with init.el and package installation

Like presumably many emacs users I have my own emacs config file ~/.emacs.d/init.el for configuring emacs the way I like. So when I start using a new machine I copy my emacs config file to it. Now, the problem is that my emacs config file depends on a few packages that I have installed via the emacs package manager, but due to the missing packages I'm unable to successfully install packages.
I can of course start emacs without my config file (emacs -q), but then the problem is that only the default repo is available, so I cannot actually install the package I need to install in order to successfully start emacs with my config file.
So what I have usually done is to temporarily comment out stuff in my emacs config file, so that I'm able to successfully install the packages, and then I can uncomment it and restart emacs with my full config. But this is cumbersome, and usually takes a few tries before I comment out all the needed stuff. Surely there must be a better way that I'm missing?
What you can do is to declare packages you use. Then add some code that runs every time you open Emacs. It checks each package from that list if it has been installed or not. When it's not, it installs it.
A quick example from my config file:
;; first, declare repositories
(setq package-archives
'(("gnu" . "http://elpa.gnu.org/packages/")
("marmalade" . "http://marmalade-repo.org/packages/")
("melpa" . "http://melpa.org/packages/")))
;; Init the package facility
(require 'package)
(package-initialize)
;; (package-refresh-contents) ;; this line is commented
;; since refreshing packages is time-consuming and should be done on demand
;; Declare packages
(setq my-packages
'(cider
projectile
clojure-mode
expand-region
helm
jinja2-mode
magit
markdown-mode
paredit
wrap-region
yaml-mode
json-mode))
;; Iterate on packages and install missing ones
(dolist (pkg my-packages)
(unless (package-installed-p pkg)
(package-install pkg)))
And you're good.
You can place the initialization elisp that installs the packages you need in a separate file, then start emacs -q, then load and evaluate the packages elisp file.
I'm using the following code, in a file of its own, to handle packages. This code also defines the packages I'm using and allows for dynamically adding and loading packages.
If you load this file first thing from your init.el, then you would probably be able to just start Emacs as usual, and missing required packages will be installed automatically.
Update
I was somewhat bothered with the way I used defvar to define the package list variable. I've done some reading and fixed the code below—now it defvar a variable my-packages-package-list and then setq it to the list of packages to install. As far as I understand, this is a more idiomatic way of defining and using variables. As a result, this code now byte-compiled without any warnings.
For those who are interested, some information of using defvar and setq may be found here and in the Emacs` manual.
(require 'package)
(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
;; ("marmalade" . "https://marmalade-repo.org/packages/")
("melpa" . "https://melpa.org/packages/")
("org" . "https://orgmode.org/elpa/")))
(setq package-archive-priorities '(("melpa" . 10)
("gnu" . 5)
("org" . 2)
;; ("marmalade" . 0)
))
(package-initialize)
(when (not package-archive-contents)
(package-refresh-contents))
;; the following code will install packages listed in myPackages if
;; they are not already installed
;; https://realpython.com/emacs-the-best-python-editor/
(defvar my-packages-package-list "List of custom packages to install.")
;;; this allows for dynamically update and install packages while
;;; Emacs is running, by modifying this list, and then evaluating it
;;; and tha mapc expression below it
(setq my-packages-package-list
'(;; add the ein package (Emacs ipython notebook)
ein
;; python development environment
elpy
;; beutify python code
py-autopep8
;; git emacs interface
magit
;; debuggers front end
realgud
;; multiple major mode for web editing
;; multi-web-mode
;; major mode for editing web templates
web-mode
;; docker modes
docker-compose-mode
dockerfile-mode
;; list library for emacs
dash
;; collection of useful combinators for emacs lisp
dash-functional
;; major modes for yaml
yaml-mode
;; major modes for markdown
markdown-mode
;; major modes for lua
lua-mode
;; major modes for fvwm config files
fvwm-mode
;; treat undo history as a tree
undo-tree
;; flychek
;; flychek-clojure
;; flychek-pycheckers
;; Clojure for the brave and true - below; amit - some packages
;; commented out by me until I'll be sure they are needed
;; makes handling lisp expressions much, much easier
;; Cheatsheet: http://www.emacswiki.org/emacs/PareditCheatsheet
paredit
;; key bindings and code colorization for Clojure
;; https://github.com/clojure-emacs/clojure-mode
clojure-mode
;; extra syntax highlighting for clojure
clojure-mode-extra-font-locking
;; integration with a Clojure REPL
;; https://github.com/clojure-emacs/cider
cider
;; allow ido usage in as many contexts as possible. see
;; customizations/navigation.el line 23 for a description
;; of ido
;; ido-ubiquitous
;; Enhances M-x to allow easier execution of commands. Provides
;; a filterable list of possible commands in the minibuffer
;; http://www.emacswiki.org/emacs/Smex
;; smex
;; project navigation
;; projectile
;; colorful parenthesis matching
rainbow-delimiters
;; solarized theme
solarized-theme
;; edit html tags like sexps
;; tagedit
;; help finding keys
which-key
;; xkcd
xkcd
;; Clojure exercises
4clojure
))
(mapc #'(lambda (package)
(unless (package-installed-p package)
(package-install package)))
my-packages-package-list)

package-install can't find icicles

I'm trying to install icicles in Emacs because I've read it makes for a more clear emacs experience. The problem is, even though I'm loading the Melpa repositories, and Checked melpa for if the package was available (it was) If I try package-install on it, it returns [no match].
I've tried package-refresh-contents to na avail. Please help with this, I could do it manually, but AUGH!
Just for context, here's the contents on my .emacs:
;; packages
(require 'package)
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("org" . "http://orgmode.org/elpa/")
("marmalade" . "https://marmalade-repo.org/packages/")
("melpa" . "https://melpa.org/packages/")))
(add-to-list 'load-path "~/.emacs.d/elisp")
(defun require-package (package)
(setq-default highlight-tabs t)
"Install given PACKAGE."
(unless (package-installed-p package)
(unless (assoc package package-archive-contents)
(package-refresh-contents))
(package-install package)))
(package-initialize)
(load-theme 'zenburn t)
(require 'php-mode)
(eval-after-load 'php-mode
'(require 'php-ext))
(add-to-list 'auto-mode-alist '("\\.json$" . js-mode))
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-safe-themes (quote ("f5eb916f6bd4e743206913e6f28051249de8ccfd070eae47b5bde31ee813d55f" default))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;;
Thanks in advance, all help is very much appreciated
Icicles is no longer distributed on ELPA or MELPA:
NOTE:
Icicles, as well as my other libraries that are on EmacsWiki, used to be obtainable also from MELPA. You may still find some of them there, but they are likely not up-to-date.
As of 2017-10, MELPA has decided to no longer accept Lisp libraries from EmacsWiki. This includes my libraries, even though these libraries are read-only (administrator lock on the wiki pages). Too bad. This means that you must download Icicles and my other libraries only from Emacs Wiki. Sorry about that. I upload Icicles files only to the wiki.
https://www.emacswiki.org/emacs/Icicles_-_Libraries
Solved the problem by doing M-x eval-buffer on my .emacs.

Emacs: can't autostart projectile installed through MELPA

I'm fairly new to emacs. In fact I'm learning the editor and trying to setup something that will replicate "go to a file inside the project" feature known from Code::Blocks or certain plugins of notepad++.
'projectile' fulfills this need, and I installed it through MELPA. Package installed properly, as I can start it with M-x projectile-global-mode and C-c p commands are recognized.
However, if I put it into my .emacs file, Emacs starts with an error:
Symbol's function definition is void: projectile-global-mode
Contents of my .emacs file are as follows:
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
(global-whitespace-mode 1)
(global-linum-mode 1)
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(projectile-global-mode 1)
When I try to (require 'projectile) first, I only end up with another error:
'File error: Cannot open load file, projectile'
I'm using Emacs 24.3.1.
How do I put this on autostart properly?
By default, Emacs initializes packages after evaluated init.el. Hence, in a standard setup, packages are not yet available while init is evaluated.
Use (add-hook 'after-init-hook #'projectile-global-mode) to enable Projectile only after packages are initialized, or explicitly initialize packages at the beginning of your init.el with the following code:
(require 'package)
(setq package-enable-at-startup nil) ; To avoid initializing twice
(package-initialize)
You have to load projectile first, e.g. by using this:
(require 'projectile)
(projectile-global-mode)
you can add
'(initial-major-mode (quote projectile-global-mode))
to your .emacs(or init.el or whatever your file is called) file in the custom-set-variable section.
Alternatively, in newer versions of emacs, the menu Options | Customize Emacs | Specific Option you can type 'initial-major-mode' and this will take you to an interface where emacs can customize itself with that setting. just remember to apply and save

Emacs Predictive - Accept with punctuation

I have successfully managed to install the predictive package for Emacs and am trying to accept the most likely correction with punctuation, which is mentioned in the manual:
http://www.dr-qubit.org/predictive/predictive-user-manual/html/Auto_002dCompletion-Mode.html
But I cannot for the life of me figure out how to set this up, I have tried the code snippet, among others (in my .Emacs):
(custom-set-variables
'(auto-completion-syntax-alist (quote (accept . word))))
And while Emacs does not complain, auto-completion-mode is off when he code is included.
When opening a file, I can see that it does not scan for auto-overlays, when the above code is in my .emacs file.
The rest of my predictive .emacs related file looks like this:
(add-to-list 'load-path "~/.emacs.d/predictive/")
;; dictionary locations
(add-to-list 'load-path "~/.emacs.d/predictive/latex/")
(add-to-list 'load-path "~/.emacs.d/predictive/texinfo/")
(add-to-list 'load-path "~/.emacs.d/predictive/html/")
;; load predictive package
(autoload 'predictive-mode "predictive.el" t)
(add-hook 'LaTeX-mode-hook 'predictive-mode)
(setq predictive-main-dict 'dict-english
predictive-predictive-use-buffer-local-dict t
predictive-auto-learn t
predictive-auto-add-to-dict t
predictive-dict-autosave t)

Problem installing Auto-Complete plugin in Emacs

I downloaded Auto-Complete from here: http://github.com/m2ym/auto-complete/downloads, I placed all the files from the .zip file in my load-path (C:\...Application Data\.emacs.d\plugins\auto-complete-1.0), and added the following to my .emacs:
;; load auto complete
(add-to-list 'load-path "~/.emacs.d/plugins/auto-complete-1.0")
(require 'auto-complete)
(global-auto-complete-mode t)
but an error message shows up:
.emacs:53:1:Error: Cannot open load file: auto-complete
I use a trailing '/' with directory names (as per file-name-as-directory). e.g.:
(add-to-list 'load-path (file-name-as-directory
(expand-file-name "~/.emacs.d/plugins/auto-complete-1.0")))
I rather doubt that's actually an issue, though.
Are your permissions appropriate for those files and directories?
Are you sure that ~ really expands to C:\...Application Data? Do C-x d ~ RET to be sure.