Emacs polymode for Markdown and Python - emacs

I use the python3 pweave library (http://mpastell.com/pweave/usage.html) for literate programming.
pweave uses as text mode markdown, as code mode python3,
and it is possible to use noweb (https://en.wikipedia.org/wiki/Noweb) literate programming syntax.
For correct syntax highlighting in emacs I aimed to use the polymode library (https://polymode.github.io/ and https://github.com/polymode).
I use emacs version26.1.
And I was able to install polymode from melpa.
Unfortunate there is no pre-existing polymode for
host-mode: markdown, inner-mode: python3, syntax: noweb
so I tried, based on documentation and the existing code, to write my one
poly-pweave-mode, by putting the following lisp code into my .emacs file.
(require 'polymode-classes)
(defcustom pm-host/pweave-text
(pm-host-chunkmode :name "pweave-text"
:mode 'markdown-mode)
"markdown host chunkmode"
:group 'poly-hostmodes
:type 'object)
(defcustom pm-inner/pweave-code
(pm-inner-chunkmode :name "pweave-code"
:head-matcher "^[ \t]*<<\\(.*\\)>>="
:tail-matcher "^[ \t]*#.*$"
:mode 'python-mode)
"noweb static python3 inner chunkmode."
:group 'poly-innermodes
:type 'object)
(define-polymode poly-pweave-mode
:hostmode 'pm-host/pweave-text
:innermode 'pm-inner/pweave-code)
(add-to-list 'auto-mode-alist '("\\.pymd" . poly-pweave-mode))
But somehow emacs is not eating this.
When I open emacs I get the following error:
Warning (initialization): An error occurred while loading `/Users/abc/.emacs':
Symbol's function definition is void: pm-host-chunkmode
To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with
the `--debug-init' option to view a complete error backtrace.
What do I wrong?
How I could get the desired polymode running?

This is the solution how to specify a markdown-python3-noweb polymode
;; define pwn polymode
(require 'poly-noweb)
(require 'poly-markdown)
(defcustom pm-inner/noweb-python
(clone pm-inner/noweb
:name "noweb-python"
:mode 'python-mode)
"Noweb for Python"
:group 'poly-innermodes
:type 'object)
(define-polymode poly-pweave-mode poly-markdown-mode
:innermodes '(pm-inner/noweb-python :inherit))
(add-to-list 'auto-mode-alist '("\\.pymd" . poly-pweave-mode))
My thank goes to Vitalie Spinu, the author of the polymode package, who helped me resolving this question!
For a detailed discussion have a look at polymode issue 180 at github.
Alternatively I found this post at emacs stack exchange: https://emacs.stackexchange.com/questions/20136/pythontex-and-auctex So, following this post, this is the solution to get to a markdown-python3-noweb mmm-mode
;; define pwn multi major modes mode
(require 'mmm-auto)
(mmm-add-classes
'((noweb-python
:submode python-mode
:face mmm-default-submode-face
:front "^<<.*>>=\n"
:back "^#$")))
(setq mmm-global-mode 'maybe)
(mmm-add-mode-ext-class 'markdown-mode nil 'noweb-python)
(add-to-list 'auto-mode-alist '("\\.pymd" . markdown-mode))
My thank belongs to Jean Pierre, whose detailed explanation in the post made it a piece of cake to get it running for my case!

Related

Emacs: Cannot open load file, go-autocomplete

I'm trying to install [gocode][1] on Emacs currently and am receiving the current error message:
Warning (initialization): An error occurred while loading `/home/darwin/.emacs':
File error: Cannot open load file, no such file or directory, go-autocomplete
To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with
the `--debug-init' option to view a complete error backtrace.
And when I run Emacs with --debug-init, I receive this (it's not too pretty):
Debugger entered--Lisp error: (file-error "Cannot open load file" "no such file or directory" "go-autocomplete")
require(go-autocomplete)
eval-buffer(#<buffer *load*> nil "/home/darwin/.emacs" nil t) ; Reading at buffer position 1831
load-with-code-conversion("/home/darwin/.emacs" "/home/darwin/.emacs" t t)
load("~/.emacs" t t)
#[0 "\205\262� \306=\203�\307\310Q\202;� \311=\204�\307\312Q\202;�\313\307\314\315#\203*�\316\202;�\313\307\314\317#\203:�\320\nB\321\202;�\316\322\323\322\211#\210\322=\203a�\324\325\326\307\327Q!\"\323\322\211#\210\322=\203`�\210\203\243�\330!\331\232\203\243�\332!\211\333P\334!\203}�\211\202\210�\334!\203\207�\202\210�\314\262\203\241�\335\"\203\237�\336\337#\210\340\341!\210\266\f?\205\260�\314\323\342\322\211#)\262\207" [init-file-user system-type delayed-warnings-list user-init-file inhibit-default-init inhibit-startup-screen ms-dos "~" "/_emacs" windows-nt "/.emacs" directory-files nil "^\\.emacs\\(\\.elc?\\)?$" "~/.emacs" "^_emacs\\(\\.elc?\\)?$" (initialization "`_emacs' init file is deprecated, please use `.emacs'") "~/_emacs" t load expand-file-name "init" file-name-as-directory "/.emacs.d" file-name-extension "elc" file-name-sans-extension ".el" file-exists-p file-newer-than-file-p message "Warning: %s is newer than %s" sit-for 1 "default"] 7 "\n\n(fn)"]()
command-line()
normal-top-level()
I've installed the Emacs (regular) autocomplete version required for gocode using the package manager (gocode isn't available on this manager by the way).
My directories if they help:
Emacs folder is called: .emacs.d:
/.emacs.d
/auto-save-list
/elpa
go-autocomplete.el
Emacs init folder:
(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-enabled-themes (quote (misterioso)))
'(inhibit-startup-screen t))
(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.
)
(when (>= emacs-major-version 24)
(require 'package)
(package-initialize)
; (add-to-list 'package-archives
; '("melpa-stable" . "http://stable.melpa.org/packages/") t)
(add-to-list 'package-archives '("marmalade" . "https://marmalade-repo.org/packages/"))
(add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/") t)
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
)
;; Update Emacs config for godoc
(setenv "PATH" "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/go/bin")
(setenv "GOPATH" "~/go")
;; calls gofmt before save
(setq exec-path (cons "/usr/local/go/bin" exec-path))
(add-to-list 'exec-path "/go/bin")
;(add-hook 'before-save-hook 'gofmt-before-save)
(defun my-go-mode-hook ()
; Call Gofmt before saving
(add-hook 'before-save-hook 'gofmt-before-save)
; Customize compile command to run go build
(if (not (string-match "go" compile-command))
(set (make-local-variable 'compile-command)
"go build -v && go test -v && go vet"))
; Godef jump key binding
(local-set-key (kbd "M-.") 'godef-jump))
(add-hook 'go-mode-hook 'my-go-mode-hook)
;; Gocode: Go aware Autocomplete
(require 'go-autocomplete)
(require 'auto-complete-config)
;; Go eldoc (via package control) REQUIRES GOCODE
(require 'go-eldoc)
(add-hook 'go-mode-hook 'go-eldoc-setup)
If anyone could help me figure out how I can get gocode to work that would be fantastic. Thank you in advance.
P.S. I can add other directories if needed.
[1]: https://github.com/nsf/gocode
The root directory of .emacs.d is not generally a part of the load-path, and recent versions of Emacs will even give the user a warning message discouraging against doing it if in fact a user did it. Create a sub-folder called lisp or hello-world and put your library inside it and then add the lisp or hello-world directory to your load-path and restart Emacs. Here is a link to the related documentation for load-path:  https://www.gnu.org/software/emacs/manual/html_node/emacs/Lisp-Libraries.html
Example (place inside .emacs file):
(add-to-list 'load-path "/path/to/my/lisp/library")

Emacs and CWB under Windows

I'm trying to use the Edinburgh Concurrency Workbench (http://homepages.inf.ed.ac.uk/perdita/cwb/) with Emacs under Windows. I have placed the file cwb.el under C:\emacs\emacs-22.3\emacs-stuff. My .emacs file is located at C:\emacs and has the following content:
(setq load-path ; Look in my own library first.
(cons (expand-file-name "C:\emacs\emacs-22.3\emacsstuff")
load-path))
(autoload 'cwb "cwb" "Run a CWB process." t)
(autoload 'cwb-file-mode "cwb" "Major mode for editing CWB source." t)
(add-hook 'cwb-load-hook
(function
(lambda ()
(setq cwb-program-name "cwb7")))) ;; only necessary if your v7 isn't
;; called cwb
Yet, when I enter "M-x cwb", I get "Cannot open load file: cwb".
I tried to follow the instruction here: http://homepages.inf.ed.ac.uk/perdita/cwb/doc/emacs.html.
Thanks
In Emacs Lisp strings, backslash is an escape character, similar to C, so "C:\emacs\emacs-22.3\emacsstuff" ends up being "C:^[macs^[macs-22.3^[macsstuff". (You can try it with either M-: or M-x ielm.)
You can either write the path with forward slashes instead ("C:/emacs/emacs-22.3/emacsstuff") or use double backslashes ("C:\\emacs\\emacs-22.3\\emacsstuff").

write mail with mutt using emacs

I am using both mutt and emacs to write mail.
I use, until recent time, this code into my .emacs :
; corrector
(add-hook 'mail-mode-hook 'flyspell-mode)
; Do not cut words
(global-visual-line-mode t)
; open mail-mode when emacs is invoked by mutt
(add-to-list 'auto-mode-alist '("/mutt" . mail-mode))
; wrap email body
(add-hook 'mail-mode-hook 'turn-on-auto-fill)
(add-hook 'mail-mode-hook 'turn-on-filladapt-mode)
But it is not working anymore. When I write a email with emacs I have no flyspell enable and the mail-mode does not wrap the text.
When I try to launch the mail-mode manually, I have a error :
File mode specification error: (void-function turn-on-filladapt-mode)
Making completion list... [2 times]
run-hooks: Symbol's function definition is void: turn-on-filladapt-mode
The problem was caused by the missing package emacs-goodies.el (in debian sid) which include filladapt.

Emacs Auctex compile error: "Use M-x make-directory RET RET to create the directory and its parents"

I am running emacs 23.3.1 on ubuntu 12.04 with auctex 11.86. Whenever I go to compile a latex document (using C-c C-c), if there are no errors, everything compiles just fine. However, if there are any errors it will tell me to use C-` to view errors, if I do so, I get this error message
Use M-x make-directory RET RET to create the directory and its parents
and it goes away after a couple seconds. Then it takes me to another screen that explains the error in the latex code. However, now I cannot simply do C-x 1 to get back to the latex code. I have to C-x C-c and restart emacs.
This is my .emacs file
(setq backup-by-copying t
backup-directory-alist '(("." . "~/.emacsBkups"))
delete-old-versions t
kept-new-versions 5
kept-old-versions 2
version-control t)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq TeX-PDF-mode t)
;;(require 'ess-site)
;;(ess-toggle-underscore nil)
(require 'whitespace)
(setq whitespace-style '(lines-tail face))
(add-hook 'c-mode-hook 'whitespace-mode)
(add-hook 'c++-mode-hook 'whitespace-mode)
(add-hook 'python-mode-hook 'whitespace-mode)
(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
(c-set-offset (quote cpp-macro) 0 nil)
(setq TeX-view-program-list '(("Evince" "evince --page-index=%(outpage) %o")))
(setq TeX-view-program-selection '((output-pdf "Evince")))
Sometimes AUCTeX gets confused parsing the log of (La)TeX compilation and isn't able to guess the correct line raising the error. In some cases AUCTeX issues an obscure message "Error occured after last TeX file closed", when there are unbalanced parentheses, in your case it suggests you to create a new directory. To help AUCTeX finding the correct line raising the error you can add the -file-line-error option to latex or pdflatex by customizing the variable LaTeX-command-style. To do this add the following code to your .emacs:
(setq LaTeX-command-style '(("" "%(PDF)%(latex) -file-line-error %S%(PDFout)")))
See also the AUCTeX FAQ:
8. Why does TeX-next-error (C-c `) fail?
When writing the log file, TeX puts information related to a file,
including error messages, between a pair of parentheses. AUCTeX
determines the file where the error happened by parsing the log file
and counting the parentheses. This can fail when there are other,
unbalanced parentheses present.
As a workaround you can activate so-called file:line:error messages
for the log file. (Those are are easier to parse, but may lack some
details.) Either you do this in the configuration of your TeX system
(consult its manual to see where this is) or you add a command line
switch to the (la)tex call, e.g. by customizing LaTeX-command-style or
TeX-command-list.

P4CONFIG with emacs

I would like to see examples of how to setup perforce, using the config file functionality where emacs is used as the diff and merge programs (P4DIFF and P4MERGE settings). Even better if this is on Windows.
I'm also struggling with getting the P4EDITOR to work correctly when using emacsclientw, specifically specifying the alternate-editor functionality.
Any tips, suggestions, example configs are very welcome.
Here's a different trick I used to use. It adds a few command line options to emacs so that you can do diffs and merges in a new emacs instance (again using ediff).
;; -diff
(defun command-line-diff (switch)
(let ((file1 (pop command-line-args-left))
(file2 (pop command-line-args-left)))
(ediff file1 file2)))
(add-to-list 'command-switch-alist '("-diff" . command-line-diff))
;; -merge
(defun command-line-merge (switch)
(let ((base (pop command-line-args-left))
(sccs (pop command-line-args-left))
(mine (pop command-line-args-left))
(merg (pop command-line-args-left)))
(ediff-merge-with-ancestor sccs mine base () merg)))
(add-to-list 'command-switch-alist '("-merge" . command-line-merge))
Just put that in your .emacs file. Then you can set your P4DIFF program to be emacs -diff and your P4MERGE program to be emacs -merge.
I'm assuming you're already using p4.el.
Here's a function that will allow you to set your p4-client-config easily:
(defun p4-go (config)
(interactive
(list (read-file-name "P4 Config file: "
(concat (getenv "HOME") "/etc/perforce/")
""
t)))
(p4-set-client-config (expand-file-name config))
t)
Then I just run M-x p4-go <RET> conf <RET>.
My ~/etc/perforce/conf file looks like:
P4CLIENT=ewarmenhoven-ppd
P4PORT=perforce.netflix.com:1666
P4USER=ewarmenhoven
P4EDITOR=emacsclient
P4DIFF=diff -dupU8
P4MERGE=~/bin/emerge
The emerge merge program is just a short little shell script that calls emacsclient appropriately:
#!/bin/bash
base=$1
sccs=$2
mine=$3
merg=$4
emacsclient -e "(ediff-merge-files-with-ancestor \"$base\" \"$sccs\" \"$mine\" () \"$merg\")"
emacsclient "$merg"
If you're using cygwin it should work just fine.
For doing diffs, if it's running from the shell then I want the output in the shell, hence just using normal diff. If it's not, I use p4-ediff, which is bound to C-x p - by default.
The awesome answer by Eric doesn't work properly in latest emacs because of welcome screen. In order to hide the welcome screen (so that you may get the diff properly) please refer Unable to hide welcome screen in Emacs.
Another nifty setting which opens the diff in regular vertical mode is setting the below config variable
(custom-set-variables
;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
'(ediff-split-window-function (quote split-window-horizontally)))