fsharp / emacs-fsharp-mode

F# Emacs mode
Apache License 2.0
208 stars 61 forks source link

.fsproj management #10

Open BitPuffin opened 9 years ago

BitPuffin commented 9 years ago

Hey!

It would be great if fsharp-mode could create and manage .fsproj files for you. As editing one by hand is really painful.

Just a suggestion

Cheers!

rneatherway commented 9 years ago

Hey, this is a good idea and actually a simple version for editing such file exists: https://github.com/simontcousins/fsproj-mode

I have been thinking about asking the author if he would like to incorporate it here. We have also been talking about making a simple unified tool that could be shared between editors.

Would you mind listing the operations you would like to perform in case we have missed any?

BitPuffin commented 9 years ago

Thanks for pointing out fsproj-mode that'll help me at least get started a bit more :+1:

I believe I saw on twitter or something a few days ago while searching that the author of fsharp-mode wants to also incorporate project management. But it seemed to be a relatively old tweet.

A tool that could be incorporated in many editors would be really nice. Basically just a command line application that let's you add and remove files etc and configure targets and what not. That would be really useful so you don't have to launch an editor at all if all you simply need to do is to add a file or assembly reference or whatever.

I'm not sure if I'm the best person to ask which operations you need to include. But basically all of the essentials: name project, add/remove source files, define targets, add/remove assembly references, add/remove library search paths. Those are probably the most common things that I find myself doing at least when I program in .NET thingies.

Cheers

rneatherway commented 9 years ago

Yes, I am the author of fsharp-mode, and I do! I meant that I was going to ask @simontcousins if he wanted to include fsproj-mode here. A view-only mode that shells out to a command-line application for modifications might be a nice way to continue with fsproj-mode.

BitPuffin commented 9 years ago

Oh, I misunderstood then, I thought you wanted to ask the dev of fsharp-mode to include fsproj-mode as a user or something :)

Yeah, that would make it much easier for other editors to support fsharp projects as well I think.

simoncousins commented 9 years ago

I had forgotten about fsproj-mode, it has been dormant for a while now!

I agree, shelling out to another app is the way to go - apart from anything else working with xml in emacs lisp is not that pleasant.

I got distracted by thinking about creating my own terminal-based text editor with a built in f# interpreter for evaluating extension scripts - with support for paket, fake and projects expressed as f# data structures (like in freya https://github.com/freya-fs/freya/blob/master/build.fsx).

So far I only have a cross-platform wrapper for ncurses and can do interesting things with terminals in f# https://github.com/simontcousins/fncurses/blob/master/demos/Worm/Program.fs :)

juergenhoetzel commented 8 years ago

Meanwhile there is Forge. I thought of writing Emacs bindings.

rneatherway commented 8 years ago

I started https://github.com/fsprojects/Projekt/, but it looks like Forge has gone further. Adding Emacs bindings would really be great!

dgellow commented 8 years ago

Hi guys. Any news on this topic?

simoncousins commented 8 years ago

I started a Forge mode for emacs here: https://github.com/simontcousins/forge.el

Last time I worked on it I think I got the new-project, new-file, add-file, remove-file, move-file, list-files, list-templates commands working. The intention is to support all of these commands (but some of them are broken in Forge (at least on my mac) and/or difficult to invoke from elisp):

;; * forge-process--new-project - Run the forge new project command ;; * forge-process--new-file - Run the forge new file command ;; * forge-process--add-file - Run the forge add file command ;; * forge-process--add-reference - Run the forge add reference command ;; * forge-process--remove-file - Run the forge remove file command ;; * forge-process--remove-reference - Run the forge remove reference command ;; * forge-process--rename-file - Run the forge rename file command ;; * forge-process--rename-project - Run the forge rename project command ;; * forge-process--list-files - Run the forge list files command ;; * forge-process--list-references - Run the forge list references command ;; * forge-process--list-project-references - Run the forge list project references command ;; * forge-process--list-gac - Run the forge list gac command ;; * forge-process--list-templates - Run the forge list templates command ;; * forge-process--move-file - Run the forge move file command ;; * forge-process--update-paket - Run the forge update paket command ;; * forge-process--update-fake - Run the forge update fake command ;; * forge-process--paket - Run the forge paket command ;; * forge-process--fake - Run the forge fake command

Nemeczek commented 8 years ago

Nice work @simontcousins - is it on melpa already? I can't find it.

What's the current standard for working with fsproj? fsharp-mode works fine for created solution but currently I really don't get how add file and get it registered within sln and fsproj.

simoncousins commented 8 years ago

It is just on my laptop and github :-) I need to do a bit more work on it before releasing to melpa as some of the commands do not work - but you can drop the files as-is into your site-lisp.

AFAIK there still isn't a nice way to create a solution from scratch without a dependency on an IDE (until there is one it is hard to take cross-platform development seriously).

I typically start new solutions by cloning Project Scaffold.

.NET Core's command line tool now supports F# (but I have not tried it - because it is .NET Core): https://docs.microsoft.com/en-us/dotnet/articles/core/tools/dotnet-new

Failing that crack open Xamarin Studio/VS Code to create the solution.

All a bit of a faff I'm afraid.

Nemeczek commented 8 years ago

@simontcousins I understand that but I missed my point. I am aware of that we need some external tool for creation of the solution. My question is do we need IDE to able to add new project to solution? And when I am working in given fsproj and I want to add new file we still need to add entry manually?

Maybe you should release some beta version, would love to test it. And you can get feedback from others as well 👍

simoncousins commented 8 years ago

AFAIK you need an IDE to add a new project to a solution.

You can use Forge to add a new or existing file to an existing fsproj, see:

Both of these work in forge.el. If you want to try forge.el just load the *.el files into you emacs session. The above Forge commands map to:

julienXX commented 7 years ago

I started a dotnet CLI mode for .NET Core which handles adding references, updating solution files and more if that can help some of you https://github.com/julienXX/dotnet.el

sleepyfran commented 2 years ago

To revive this a bit, I have two functions that I use to have a the basic bits of project management inside of Emacs:

(defun fsharp-add-this-file-to-proj ()
  "Adds the path of the current file to the .fsproj relative to it"
  (interactive)
  (when-let* ((file-long (f-this-file))
              (project (fsharp-mode/find-fsproj file-long))
              (project-file (f-filename project))
              (project-path (string-replace project-file "" project))
              (file-relative-path (string-replace project-path "" file-long)))
    (with-current-buffer (find-file-noselect project)
      (goto-char (point-min))
      (unless (re-search-forward file-relative-path nil t)
        (when (and (re-search-forward "<Compile Include=" nil t)
                   (re-search-backward "<" nil t))
          (insert (format "<Compile Include=\"%s\" />\n        " file-relative-path))
          (save-buffer))))))

(defun fsharp-remove-this-file-from-proj ()
  "Removes the path of the current file from the .fsproj"
  (interactive)
  (when-let* ((file-long (f-this-file))
              (project (fsharp-mode/find-fsproj file-long))
              (project-file (f-filename project))
              (project-path (string-replace project-file "" project))
              (file-relative-path (string-replace project-path "" file-long)))
    (with-current-buffer (find-file-noselect project)
      (goto-char (point-min))
      (when (re-search-forward (format "<Compile Include=\"%s\" />" file-relative-path) nil t)
        (move-beginning-of-line 1)
        (kill-line)
        (kill-line)
        (save-buffer)))))

Based on this post but modified to properly handle relative paths since it was always adding just the name of the file to the .fsproj file instead of the relative path.

Note for folks who want to use it: It requires Emacs 28.1 since it uses string-replace, but you can always switch it with replace-regexp-in-string if you use any version below.

@juergenhoetzel would something like this make sense inside of the library? I was thinking of adding this in the project, but not sure if it belongs to it or not 😃