running `org-export-as-html' in emacs batch mode - emacs

When using `org-export-as-html' in batch mode the html produced from code blocks has no syntax coloring.
How do I enable the syntax coloring in batch mode?
EDIT:
From the terminal I run emacs --script make.el.
In make.el I include org and org-html and eventually call (org-export-as-html 3)
The following will bold/underline keywords but still no color:
(add-to-list 'load-path "~/elisp/org/contrib/lisp")
(require 'htmlize)
(setq c-standard-font-lock-fontify-region-function 'font-lock-default-fontify-region) ;; fixes bug
(org-export-as-html 3)
EDIT 2:
A couple more things I've tried - they make no difference:
(setq org-src-fontify-natively t)
(org-babel-do-load-languages 'org-babel-load-languages '((java .t)))
I've also tried loaded my entire .emacs
I'm using GNU Emacs 24.3.1 and Org 7.9.2

Apparently, if you use the color-theme library, then (for occult reasons about which I have no clue yet) you can have colored outputs through htmlize when exporting in batch mode.
For example, evaluating the following code in an org buffer to export makes htmlize use colors defined by means of a theme, and that works when exporting both in batch mode and interactively (by creating a temporary frame and setting the appropriate color theme to avoid messing up the frame containing the org buffer to export):
(require 'cl) ;for `lexical-let'
(add-hook
;; This is for org 8.x (use `org-export-first-hook' for earlier versions).
(make-local-variable 'org-export-before-processing-hook)
(lambda (backend)
(add-to-list (make-local-variable 'load-path) (expand-file-name "./etc"))
(require 'color-theme)
(color-theme-initialize)
(when (display-graphic-p) ;Are we running in interactive mode?
;; If so, create a temporary frame to install the color theme used by
;; htmlize:
(lexical-let ((buff (switch-to-buffer-other-frame (current-buffer)))
(frame (selected-frame)))
(setq color-theme-is-global nil)
(make-frame-invisible frame)
;; Schedule deletion of temporary frame:
(add-to-list
;; The following is for org 8.x (earlier versions use other hooks like
;; `org-latex-final-hook').
(make-local-variable 'org-export-filter-final-output-functions)
(lambda (string backend info) (delete-frame frame)))))
;; Install color theme.
(color-theme-blippblopp)))

Related

Is there a way to use Rmarkdown in Spacemacs?

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.

How to enable `fill-column-indicator` on startup

I am using Aquamacs on OS X 10.9.4. I have the following lines in my Preferences.el file
(which is similar to the .emacs init file):
(add-to-list 'load-path "~/.emacs.d/")
(require 'fill-column-indicator)
(setq-default fci-mode t)
I use M-x fci-mode to manually toggle the column indicator.
How can fci-mode be enabled on startup using Aquamacs?
Don't put ~/.emacs.d itself in your load-path. Always use a sub-directory.
e.g.: use ~/.emacs.d/lisp/fill-column-indicator.el and:
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp"))
(require 'fill-column-indicator)
This library doesn't provide a global minor mode, but you can make one yourself like so:
(define-globalized-minor-mode my-global-fci-mode fci-mode turn-on-fci-mode)
(my-global-fci-mode 1)
or toggle it interactively with M-x my-global-fci-mode RET
You should remove (setq-default fci-mode t).
fci-mode is not global, so you could use a mode hook. If, for example, your opening document on startup is emacs-lisp-mode, you could place something like this inside your Preferences.el file.
(add-hook 'emacs-lisp-mode-hook (lambda ()
(fci-mode 1)
))
You will need to use a mode hook for each major mode; or, you will need to modify fci-mode by adding a global setting.
For anyone who is interested in looking at the source-code, here is the link to the Github repository: https://github.com/alpaker/Fill-Column-Indicator
With Emacs 27 comes the display-fill-column-indicator-mode minor mode, which obsoletes the fill-column-indicator package. You can add:
(add-hook 'prog-mode-hook (lambda ()
(display-fill-column-indicator-mode)))
to ~/.emacs to enable it for prog-mode buffers, or:
(global-display-fill-column-indicator-mode)
to enable it globally. To toggle it, use M-x display-fill-column-indicator-mode.

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)

Emacs ess auto-complete

I am a R user, I want to use R in emacs. But, I am in trouble with customizing ess in emacs. I have installed the auto-complete packages and the latest ess in my emacs. But when I run r in emacs, the auto-complete don't work well.
When I type app, I suppose to show like the image in (http://www.emacswiki.org/pics/static/ess-ac3) , but in my emacs neither of the auto-complete nor the yellow part shows.
My OS: ubuntu 12.04 amd64
my ~/.emacs file
;; Auto-complete
(add-to-list 'load-path "~/.emacs.d/site-lisp")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/site-lisp/ac-dict")
(ac-config-default)
; ess-site
(add-to-list 'load-path "/usr/share/emacs/site-lisp/ess")
(require 'ess-site)
(setq ess-eval-visibly-p nil)
(setq ess-ask-for-ess-directory nil)
I recently started using ESS on Windows, and struggled with the same issue. I don't know all of the ins and outs but recent versions of ESS suggest using company-mode rather than auto-complete-mode. This minimal setup seems to have autocomplete working quite well for me on the following setup:
Windows 10 x64
R 3.4.3 x64
Emacs 25 x64 installed normally
MELPA repo enabled in init.el
package-install [RET] company
package-install [RET] ess
open a new R file in some directory
M-x company-mode to enable company-mode in the current buffer
`C-c C-z' to start an inferior R process
At this point, with the init.el file shown below, R completion is working, completing function calls, and package members. I think more configuration is needed to tailor it to your liking, but getting to this point took me long enough I consider it a success
init.el:
(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
(not (gnutls-available-p))))
(proto (if no-ssl "http" "https")))
(add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
)
(package-initialize)
;; emacs controlled settings
(custom-set-variables
'(package-selected-packages (quote (company ess)))
'(show-paren-mode t)
'(tool-bar-mode nil))
(custom-set-faces
'(default ((t (:family "Consolas" :foundry "outline" :slant normal :weight normal :height 113 :width normal)))))
(require 'company)
Auto-complete works for me with this setting
(setq ess-use-auto-complete t)
I got the same problem and the following code worked for me:
(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)
(package-initialize) ;load and activate packages, including auto-complete
(ac-config-default)
(setq ess-use-auto-complete 'script-only)
;;if not working, use the following instead of (setq ess-use-auto-complete 'script-only)
;;(global-auto-complete-mode t)

emacs auto-complete don't work with jde

I want to develop java in emacs. I install ecb, jde and auto-complete extensions. Each one works well without starting others. But when i want to use them together, some problem happened.
auto-complete-mode doesn't auto start with jde, I need to start it by M-x auto-complete-mode. If without jde, auto-complete-mode will auto start
When I manually start the auto-complete-mode in jde, the auto complete is not work well. It just auto complete the word that is appeared.
Here is my .emacs content:
(global-linum-mode 1)
(setq linum-format "%2d| ")
(setq default-tab-width 4)
(setq debug-on-error t)
;;no backup file
(setq make-backup-files nil)
(setq debug-on-error t)
;;auto complete config
(add-to-list 'load-path "D:/emacs-24.1/custom_el/auto-complete-1.3.1")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "D:/emacs-24.1/custom_el/auto-complete-1.3.1/dict")
(ac-config-default)
(setq stack-trace-on-error t)
(add-to-list 'load-path (expand-file-name "D:/emacs-24.1/custom_el/jdee-2.4.0.1/lisp"))
(add-to-list 'load-path (expand-file-name "D:/emacs-24.1/custom_el/cedet-1.1/common"))
(add-to-list 'load-path (expand-file-name "D:/emacs-24.1/custom_el/elib-1.0"))
(add-to-list 'load-path' "d:/emacs-24.1/custom_el/ecb-2.40")
;; Initialize CEDET.
(load-file (expand-file-name "D:/emacs-24.1/custom_el/cedet-1.1/common/cedet.el"))
(load-file (expand-file-name "D:/emacs-24.1/custom_el/ecb-2.40/ecb.el"))
(require 'ecb)
(ecb-activate)
(ecb-byte-compile)
;; If you want Emacs to defer loading the JDE until you open a
;; Java file, edit the following line
(setq defer-loading-jde nil)
;; to read:
;;
;; (setq defer-loading-jde t)
;;
(if defer-loading-jde
(progn
(autoload 'jde-mode "jde" "JDE mode." t)
(setq auto-mode-alist
(append
'(("\\.java\\'" . jde-mode))
auto-mode-alist)))
(require 'jde))
;; Sets the basic indentation for Java source files
;; to two spaces.
(defun my-jde-mode-hook ()
(setq c-basic-offset 2))
(add-hook 'jde-mode-hook 'my-jde-mode-hook)
(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.
'(ecb-options-version "2.40")
'(ecb-primary-secondary-mouse-buttons (quote mouse-1--C-mouse-1)))
(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.
)
The version info is :
emacs : 24.1
auto complete : 1.3.1
ecb : 2.40
cedet : 1.1
elib : 1.0
jdee : 2.4.0.1
To auto-start auto-complete-mode with jde-mode, you need to add jde-mode to ac-modes:
(push 'jde-mode ac-modes)
Then you need to add a JDEE-specific source to ac-sources. I'm not sure of the extent of JDEE integration with Semantic, you may be able to use the pre-defined source for it:
(add-hook 'jde-mode-hook (lambda () (push 'ac-source-semantic ac-sources)))
If not, you may need to define a specialized source with ac-define-source. See auto-complete-config.el for examples.