How to change Coq Version in Proof General? - emacs

I have some code that only compiles coq code in Coq 8.09.0 . The version that I normally use is the most up-to-date version now which is Coq 8.11.0. I was able to create a new environment using opam switch and installed Coq 8.09.0 there. I successfully compiled all of the files with this version; however, I can't use proof general in emacs as it is still using Coq 8.11.0. I was wondering how I could make Proof General use a different opam instance using opam switch in Emacs. I have tried doing the following in the eshell
opam switch vst
eval $(opam env)
where vst is the name of the switch as seen in the output of opam switch in my terminal:
# switch compiler description
4.10.0 ocaml-base-compiler.4.10.0 4.10.0
default base-bigarray.base,base-threads.base,base-unix.base,ocaml.4.02.3,ocaml-config.1 default
-> vst ocaml-base-compiler.4.09.0 vst
However, the output of the eval $(opam env) line is the following:
Symbol’s function definition is void: opam
Which doesn't make sense since it understands what opam means as it was able to do the first command fine. Is there a proper way of doing opam switch to change what emacs uses? Is there a way to explicitly tell Proof General which instance of Coq it should use? Should I just uninstall Coq 8.11.0 and install Coq 8.09.0 directly using pacman (I am using manjaro)?

Using M-x and searching for "opam version" gave me the promising option
tuareg-opam-update-env
which allows one to switch environments. Doing this to switch to vst before opening a coq file and not autochecking the version of Coq seemed to work fine. Of course, this assumes one has tuareg already installed.

Related

How to get started with OCaml on VSC?

I started learning OCaml several days ago. I installed everything and tested a small program on Atom which worked ok.
But I don't really understand how to work on VSC. I created a file 'test.ml',but how can I run it ?
Thanks in advance
Assuming VSC is Visual Studio Code (and you're on a Unix-like system):
If you want editing support such as auto-completions, you need to install OCaml Platform extension for VS Code by following installation steps outlined here. Note that the instructions indicate that you need to also have ocaml-lsp-server installed.
If you need to run test.ml as a program, you should do in the VS Code terminal:
$ ocamlc -o test test.ml # compile 'test.ml' into an executable 'test'
$ ./test # to run the program
Note that VS Code doesn't have a ready button to run an OCaml file as an executable (not yet at least).
Newcomers to OCaml are recommended to explore language either with ocaml or utop REPL.
How to get utop: Assuming you have opam installed, you should opam install utop. Aforementioned opam is a package manager for OCaml, that can also help you manage OCaml versions and is indispensable if you want to get serious about OCaml development.
Then you'll be able to launch utop in terminal, and inside utop, you can execute test.ml with
#use "test.ml"
assuming that utop was launched from the folder containing test.ml.
You should be able to do the same with ocaml REPL that is installed along with OCaml compiler, but it's much less convenient.

Coq IDE icon missing from favorites

I installed Coq and Coq IDE from here. Everything went smooth.
I launched the Coq IDE from terminal, then I right clicked it to add it to my favorites and that was not possible. When I looked for its icon in my programs it wasn't there. I'm on Ubuntu 18.04, can it be done?
You can create your own coqide.desktop in ~/.local/share/applications by imitating the ones present in /usr/share/applications.
The difficulty is that the opam installation may include multiple switches, each with one version of Coq. Thus it is not clear what binary must be pointed to by the shortlink you want to create.
I see two solutions:
choosing the version of Coq present in the current global opam switch. That's what I used for a few months a year ago. If the current opam switch does not contain a Coq binary, launching CoqIDE from the shortlink silently fails. I think I used a command similar to zsh -ic coqide (because zsh is my main shell, you may adapt this command to your own shell). I call zsh so that it loads the opam environment and can find the right coqide. The -i may not be necessary, but I remembered that without it, zsh was not loading the opam environment in my case.
choosing the version of Coq present in a given switch. You just have to adapt the previous point so that the right switch is selected before calling coqide. This gives
zsh -ic "eval $(opam env --switch myswitch) coqide"
I am not sure that running an executable by calling the shell is a good practice (I would say it is not), but at least it works and I do not see how to load the opam environment without such a hack.

Elpy to allow pyenv to work on a project basis

I've used Emacs for all my coding projects so far. Soon I will start some python projects for the first time and would love to stick to Emacs for these as well.
I was looking into elpy which seems to provide already alot of desired functionality. The part I was not able to figure out completely is the following. I like to define virtual environments and python version to be used on a project basis. Let's say I start a project A, then I would use pyenv-virtualenv or pyenv-virtualenvwrapper to set it up
pyenv virtualenv 3.4.2 my-virtual-env-3.4.2
by doing this I've linked the python version 3.4.2 to that specific virtualenv / project. I have two questions regarding this in combination with elpy.
Question: This is a rather basic one. All the above can be achieved via the terminal. What is the advantage to emacs to support this? The workflow for me would be: Create project with associated virtualenv and python version. Activate virtualenv and start coding in emacs. If I need to install a package I will run pip in the terminal to ensure virtualenv is captured properly. There must be a reason why it's beneficial to support this in emacs. With my lack of knowledge I just don't see it :)
As pointed out there is for sure a good reason why we want emacs / elpy to support this. My second question would then be
**Question: How can I achieve this in emacs? Lokks like this blog has a solution. I was wondeirng if someone already tried this setup if it is a neat solution with makes sense conceptually. **
Well I strongly guess the goal is to use more features than just syntax highlighting: flycheck/flake8/linting, refactoring, elpy's test runner to use the right python version, install a pip package directly from emacs, stuff like this. You can carry on doing this in the terminal, but once you want an emacs feature, you'll need to set it up.
I found two modes to do that (see wikemacs python page and doubled-checked on melpa): pyenv-mode (in melpa) and pyenv-mode-auto (change the version when there is a .python-version file).

How to install Coq

I have been installing Coq using the download links from the https://coq.inria.fr/ for both Windows and Mac. However, when I try coqc or coqtop on terminal or command prompt I get error messages saying that the command is not found. Although with that being said, I can still run Coq almost perfectly fine on the Coq IDE but when I compile buffer, in particularly the exercises from Software Foundations, i get the following message.
Running: coqc -I '/Users/zhangsheng/Desktop/G/repos/Coqy/cis500' '/Users/zhangsheng/Desktop/G/repos/Coqy/cis500/Basics.v' 2>&1
From what I understand, 2>&1 seems to be some form of misdirection and I feel that is the reason why coqc and coqtop don't seem to work on my terminal/command prompt.
Could someone kindly suggest the 'best' way to install Coq on either Mac or Windows or both such that I don't get the problems I mentioned above?
Although I am not a Windows or OSX user, I imagine that you're having this problem because the Coq installer does not update the system's PATH variable. This variable is a list of directories used by the terminal to look up the programs corresponding to commands you type. If you don't want to install Coq via a different method, you should probably find where the coqc and coqtop binaries are installed, and add these directories to your PATH. Here are a few references on how to do this: OSX, Windows.

Using edebug for elisp fails on can't find library

Trying to use edebug to work on an emacs lisp library. I can effectively set breakpoints and break on them when I run the defun, unfortunately when I use i to step into something, I get the error:
Can't find library /usr/share/emacs/23.3/lisp/emacs-lisp/cl-macs.el
It's not lying, that library doesn't exist, only the compiled version (.elc) exists. It was installed using:
apt-get install emacs23-nox
Any ideas on how to get it going?
On a Debian-derived distro, the bare emacs23 package does not include the Elisp sources (nor any documentation, etc). To install them, sudo apt-get install emacs23-el