Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dir-locals and ship suggested helper hooks instead. #6556

Merged
merged 7 commits into from
Feb 19, 2018

Conversation

SkySkimmer
Copy link
Contributor

Alternative to #1136.

People interested in those functions can copy coqdev.el somewhere and load it, or copy parts of it to their init. Those not interested can just ignore it.

.dir-locals led to issues with unsafe local variable warnings. With
this method the user is opting in to running this code so there are no warnings.
@SkySkimmer SkySkimmer added kind: infrastructure CI, build tools, development tools. needs: review part: tools Coqdoc, coq_makefile, etc. labels Jan 6, 2018
@Zimmi48
Copy link
Member

Zimmi48 commented Jan 6, 2018

Copy somewhere, WDYM? Emacs users that are not Emacs expert might need a bit more documentation on how to use this. Can one tweak there .emacs file to load this file without moving it anywhere else? (So as to keep in sync with the potential evolution of this file.)

@RalfJung
Copy link
Contributor

RalfJung commented Feb 8, 2018

I'd be very happy for this to be merged so that I can finally git commit in Coq without annoying warnings by emacs. :)

The label seems wrong though, it seems this needs some additional work by @SkySkimmer to explain somewhere the exact procedure to configure emacs appropriately? I certainly wouldn't know where "somewhere" is. ;-)

@Zimmi48
Copy link
Member

Zimmi48 commented Feb 8, 2018

I talked to @letouzey who would be favorable to merging this as well.

@SkySkimmer
Copy link
Contributor Author

TBH I was waiting for someone to say they were interested in this approach before doing more work on it.

@RalfJung
Copy link
Contributor

RalfJung commented Feb 8, 2018

Fair enough :)

@SkySkimmer
Copy link
Contributor Author

Copy somewhere, WDYM? Emacs users that are not Emacs expert might need a bit more documentation on how to use this. Can one tweak there .emacs file to load this file without moving it anywhere else? (So as to keep in sync with the potential evolution of this file.)

It's just a regular emacs package (although a very Coq developer specific one), you put it in the load path (or add to the load path to include it) and (require 'coqdev) or (load "coqdev").

@Zimmi48
Copy link
Member

Zimmi48 commented Feb 9, 2018

OK so for instance:

(add-to-list 'load-path "~/coq/dev/tools/")
(require 'coqdev)

Can you put this in the comments at the top of the file? And also mention the existence of this file in the relevant section of dev/README? It would probably be worth checking whether the other two Emacs files in this directory still make sense BTW and merge this into coqdev.el if they do...

@SkySkimmer SkySkimmer added the needs: progress Work in progress: awaiting action from the author. label Feb 10, 2018
@SkySkimmer SkySkimmer removed the needs: progress Work in progress: awaiting action from the author. label Feb 11, 2018
@SkySkimmer
Copy link
Contributor Author

It would probably be worth checking whether the other two Emacs files in this directory still make sense BTW and merge this into coqdev.el if they do...

The backtrace regex is very mergeable, objects.el not so much IMO. objects.el came up in #819 but I didn't remove it due to inertia. If it should be removed let's do it in another PR.

@Zimmi48 Zimmi48 added this to the 8.8 milestone Feb 11, 2018
@Zimmi48
Copy link
Member

Zimmi48 commented Feb 12, 2018

I am very satisfied by the documentation and completely incompetent when it comes to reviewing Elisp. @JasonGross: would you do it?

@Zimmi48 Zimmi48 requested a review from JasonGross February 12, 2018 13:23
@SkySkimmer
Copy link
Contributor Author

I am very satisfied by the documentation and completely incompetent when it comes to reviewing Elisp. @JasonGross: would you do it?

Maybe we could get comments from PG people? @Matafou @cpitclaudel I don't know who else is there.

@Matafou
Copy link
Contributor

Matafou commented Feb 13, 2018

LGTM. Good solution.

Copy link
Contributor

@cpitclaudel cpitclaudel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I took a look.

(defun coqdev-setup-compile-command ()
"Setup `compilate-command' for Coq development."
(when-let ((dir (coqdev-default-directory)))
(setq-local compile-command (concat "make -C " dir))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want to shell-quote-argument on dir, in case it contains spaces.


(defun coqdev-setup-compile-command ()
"Setup `compilate-command' for Coq development."
(when-let ((dir (coqdev-default-directory)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when-let is Emacs 25+, but the default is still 24.5 on Debian and Ubuntu

(expand-file-name dir)))

(defun coqdev-setup-compile-command ()
"Setup `compilate-command' for Coq development."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compile-command, I think, not compilate


(defun coqdev-default-directory ()
"Return the Coq repository containing `default-directory'."
(when-let ((dir (locate-dominating-file default-directory "META.coq")))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when-let is Emacs 25+, but the default is still 24.5 on Debian and Ubuntu

Specifically `camldebug-command-name' and `ocamldebug-command-name'."
(when-let ((dir (coqdev-default-directory)))
(setq-local camldebug-command-name (concat dir "dev/ocamldebug-coq"))
(setq-local ocamldebug-command-name (concat dir "dev/ocamldebug-coq"))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expand-file-name is usually better than concat

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concat is shorter and we already expanded in coqdev-default-directory, is there still some use we can get out of expand-file-name?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too much. I don't think expand-file-name is guaranteed to return a path ending with a "/", but in practice it likely does in most cases.

(when-let ((dir (coqdev-default-directory)))
(setq-local camldebug-command-name (concat dir "dev/ocamldebug-coq"))
(setq-local ocamldebug-command-name (concat dir "dev/ocamldebug-coq"))))
(add-hook 'hack-local-variables-hook #'coqdev-setup-camldebug)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that hack-local-variables-hook is the best to use here. Maybe just tuareg-mode-hook? Or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that hack-local-variables-hook is the best to use here. Maybe just tuareg-mode-hook? Or am I missing something?

ocamldebug reads ocamldebug-command-name after moving to the ocamldebug buffer (creating it if it doesn't already exist). If newly created the buffer is in fundamental-mode at that time. So setting the variable only in ocaml files won't have an effect.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks. That sounds like an ocamldebug bug.
In that case, since that hook will run in al buffer, it might be better to check the buffer's name before running the actual body of the function.

(defun coqdev-setup-tags ()
"Setup `tags-file-name' for Coq development."
(when-let ((dir (coqdev-default-directory)))
(setq-local tags-file-name (concat dir "TAGS"))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: when-let, concat, and hack-local-variables

;; even though PG sets it with `setq' when there's a _Coqproject.
;; Also makes sense generally, so might make it into PG someday.
(make-variable-buffer-local 'coq-prog-args)
(setq-default coq-prog-args nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a couple files ((C)Morphisms.v and some test suite files) there are file local arguments which we don't want to override, but we don't want to false positive detect the presence of file local arguments when PG set them from _CoqProject in another file (eg the files in Init/, or some 3rd party file).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I understand the buffer-local part; but why do you set it to nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case PG modified it before us.

;; are recognized and can be jumped from easily in the *compilation*
;; buffer.
(defvar compilation-error-regexp-alist-alist)
(defvar compilation-error-regexp-alist)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need a to require the file that defines these variables; defvar-ing them is not enough to be able to change them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need a to require the file that defines these variables; defvar-ing them is not enough to be able to change them.

How about (with-eval-after-load 'compile ...)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd go for (require 'compile), but the with-eval-after-load form works fine too.

@SkySkimmer SkySkimmer added the needs: progress Work in progress: awaiting action from the author. label Feb 13, 2018
@SkySkimmer
Copy link
Contributor Author

I'm going to leave the concat and hack-local-variables barring further comments.

@SkySkimmer SkySkimmer removed the needs: progress Work in progress: awaiting action from the author. label Feb 13, 2018
;; following to your init:

;; (add-to-list 'load-path "/path/to/coqdev/")
;; (require 'coqdev)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add the full path, I think; unless you have > 1 files, it's enough to pass the file name to `require'.

@herbelin
Copy link
Member

Hi, seeing emacs expert gathered in this thread, may I bounce on the discussion to ask whether someone would have a solution for making C-x C-a C-b work in emacs when ocamldebugging packed modules (either with Tuareg's ocamldebug.el - as reported here - or with the camldebug.el file released with OCaml, but after all, why not also with an ad hoc emacs file for Coq developers such as discussed in this PR).

This seems a bit tricky to do since emacs has to send something like break @ MyModule.MyFile # 324. to ocamldebug, where MyModule is the name of the pack, and there seems to be no canonical way to get this name in general.

In the case of Coq however, the name of the module is the basename of the .mlpack file lying in the same directory as the current directory and which mentions the module name corresponding to the current .ml file in its list of modules to include, e.g. Ground_plugin when debugging say file plugins/firstorder/sequent.ml, since Sequent occurs in plugins/firstorder/ground_plugin.mlpack. This is why I wondered if maybe, even if a generic Tuareg-level or OCaml-level solution is difficult to get, at least something could be done at the level of coqdev.el??

@maximedenes
Copy link
Member

@SkySkimmer Do you consider this ready or do you plan to address @cpitclaudel 's comments?

@SkySkimmer
Copy link
Contributor Author

I think it's ready.

@maximedenes maximedenes merged commit d9cb50d into coq:master Feb 19, 2018
@SkySkimmer SkySkimmer deleted the no-dir-locals branch February 19, 2018 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: infrastructure CI, build tools, development tools. part: tools Coqdoc, coq_makefile, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants