Git Product home page Git Product logo

zig-mode's People

Contributors

andreaorru avatar bbuccianti avatar cademichael avatar dedifferentiator avatar dpathakj avatar eric-p-hutchins avatar erikarvstedt avatar hejsil avatar ilohmar avatar jacobly0 avatar jcs090218 avatar jdpage avatar jiacai2050 avatar joachimschmidt557 avatar juergenhoetzel avatar mdsteele avatar mega-dean avatar mgxm avatar michaelbartnett avatar nitinprakash96 avatar noisegul avatar purcell avatar saikyun avatar skangas avatar syohex avatar tealeg avatar theothornhill avatar travv0 avatar ve-nt avatar xuchunyang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zig-mode's Issues

No ansi-coloration on the *zig-fmt* output

When an error occurst in zig fmt the compilation buffer doesn't interpret the ASNI colour codes in the output, and looks kind of ugly (and somewhat hard to read) as a result.

Support ast check when formatting

There should be a way to configure this change:

diff --git a/zig-mode.el b/zig-mode.el
index de7ff92..6adca7d 100644
--- a/zig-mode.el
+++ b/zig-mode.el
@@ -110,7 +110,7 @@ If given a SOURCE, execute the CMD on it."
 
 (reformatter-define zig-format
   :program zig-zig-bin
-  :args '("fmt" "--stdin")
+  :args '("fmt" "--stdin" "--ast-check")
   :group 'zig-mode
   :lighter " ZigFmt")
 

zig-run should save the current buffer

First of all thank you so much for this package! ❤️

I just wrote my own function to save the current buffer when I execute zig-run with C-x C-r in doomemacs:

(use-package! zig-mode
  :config
  (defun my/save-buffer-and-execute-zig-run ()
    "Save the current buffer and execute `zig-run`."
    (interactive)
    (save-buffer)
    (zig-run))

  (define-key zig-mode-map (kbd "C-c C-r") #'my/save-buffer-and-execute-zig-run))

Without this most of the time I found myself pressing C-c C-r only to realise that I haven't saved the file yet.

Should zig-run always save the buffer when it is executed? I'd be happy to send in a PR but wanted to check first before I sent one.

zig-format-on-save: File digest doesn't match, so undo history will be discarded

Sometimes, the following would happen on save and result in losses of undo-history.

It is determined that zig-format-on-save is the culprit, and setting it to nil can be a workaround.

buffer-undo-list is not empty. Do you want to recover now? (y or n) y
File digest doesn’t match, so undo history will be discarded.

Fix broken indentation

Example, typing this:

const MultibootHeader = packed struct {
    magic:    usize,
    flags:    usize,
    checksum: usize,
};
  • Struct members are aligned to the opening brace by default, and they shouldn't.
  • Default indentation should be 4 spaces instead of 2.

zig-run for files with external dependencies

Let's say I have src/main.zig with following:

const std = @import("std");
const zap = @import("zap");

...

I have zap defined in build.zig & build.zig.zon, zig build succeeds.
But when I try to zig-runfrom Emacs it fails with:

main.zig:2:21: error: no package named 'zap' available within package 'root'

I probably know why it happens (sorry I am relatively new to Zig), because zig run does not play well with build.zig. But doesn't this make zig run and zig-run Emacs function useless for larger (and practical) projects?

How do you run your code from within Emacs while making projects with Zig?

Add syntax highlighting for block labels

Emacs c-mode applies font-lock-constant-face to labels (e.g. foo:) and label references (e.g. goto foo;). We should have zig-mode do something similar for e.g. blk: { ... } and break :blk.

Indentation function doesn't handle if expressions well

I don't have my config setup to format on save so I rely on the mode indentation a lot, and it currently will produce this:

fn sign(i: i32) i32 {
    return if (i == 0)
        0
        else if (i > 0)
        -1
        else
        -1;
}

While the preferred style according to zig fmt would be:

fn sign(i: i32) i32 {
    return if (i == 0)
        0
    else if (i > 0)
        -1
    else
        -1;
}

[Request] Emacs 29 tree sitter mode

With Emacs 29.1 being released, Tree Sitter support is now natively in Emacs. However, to use it there needs to be a dedicated major mode extending the base mode. In this case there would need to be a zig-ts-mode. Would that be possible?

zig-test-buffer: don't use release-fast?

Is there any rationale for using release-fast for zig-test-buffer? Personally, I would think that testing should use the debug release mode by default to catch any illegal behaviour, since that's what testing should flag out.

Zig project run

Feature request

zig-mode currently exposes zig-run, which creates an executable from the current buffer and runs it immediately.
However, for bigger projects, there is usually a buils.zig with a run step, which could be invoked via zig build run.

It would be nice to have an ability to invoke that project-level run.

Motivation

build.zig is super common and having this improves developer experience, making edit-run-loop shorter.

Details

run step is a custom thing, which is not always available. We can have a defcustom for it with a default value and then users can either configure it in their configs or dir-locals.

We can expose zig-project-run (bound to C-c C-p or something, have no strong preferences).

Background

Contribution

I can work on a PR for this.

Why does the reformatter dependency has a version?

Hello, since #51, zig-mode uses reformatter.el for running the formatter.

One thing I noticed is that zig-mode depends on at least version 0.6 of the package:

;; Package-Requires: ((emacs "24.3") (reformatter "0.6"))

while the latest version of reformatter is 0 at present:

;; Package-Version: 0

Apparently reformatter.el has no version yet, but 0.6 is bigger than 0, so the latest version of reformatter.el is considered outdated.

Is there any reason @joachimschmidt557 specified 0.6 as the minimum version? Is it just a mistake? If so, I would send a PR to set the minimum version to 0.

Replace this with a cc-mode derived mode

Replacing this mode with a cc-mode derived mode would provide better integration with other emacs packages for c-like languages and allow users cc-mode configuration to work in zig-mode.

customize-mode compatibility

I typed customize-mode to add something to the hook, only to find that there wasn't one. Is there something I'm missing?

Using new `rx` features means the minimal requirement is emacs 27

The new zig-mode failed to compile on older version like 26.3. The reason is that emacs 27's rx's regexp and new literal accept arbitrary lisp as arguments while older ones only accept string known at compile time.

So we need to either bump the minimal requirement to 27 or fix it (e.g. by wrapping the entire file inside a macro)

Deprecated zig flags for testing

Zig version: 0.6.0+53c63bdb7 on Linux 5.8.14-arch1-1

Running M-x zig-test-buffer returns

Compilation started at Tue Oct 13 16:52:15

zig test /home/username/hello/main-testing.zig --release-fast
error: unrecognized parameter: '--release-fast'

Compilation exited abnormally with code 1 at Tue Oct 13 16:52:15

because looks like at some point flags --release-* were replaced with an option -O [mode]

$ zig test --help
  ...
  -O [mode]                 Choose what to optimize for
    Debug                   (default) Optimizations off, safety on
    ReleaseFast             Optimizations on, safety off
    ReleaseSafe             Optimizations on, safety on
    ReleaseSmall            Optimize for small binary, safety off
  ...

lsp-mode is turned off for buffer on buffer save

When I have zig-mode enabled for a buffer and save that buffer while lsp-mode is enabled, LSP seems to turn off (the icon disappears from the modeline, and completions no longer work).

Distribution: Debian GNU/Linux bullseye/testing
Emacs version: 27.1
Doom Emacs version: doomemacs/doomemacs@f7293fb6
zig-mode version: 20201022.955

tramp support for formatting

While trying out zig-mode on doom emacs I tried it with some remote tramp.
Build and run commands work fine but the mode tries to run the formatting command on my host and not on my remote.

On the screenshot bellow you can see that I can run tests without issue but the formatting does not work

image

Use reformatter.el for `zig fmt`

https://github.com/purcell/reformatter.el provides an easy interface to provide idiomatic formatting commands. Using this library would make it would be possible to move a lot of the code which deals with zig fmt from this package to reformatter.el. Of course, this means that this mode has one more Elisp package as a dependency.

Auto indentation fails on K&R style curly braces

When trying to write:

const std = @import("std");
pub fn main() void
{
    std.debug.warn("hello");
}

The auto indenter turns it into:

const std = @import("std");
pub fn main() void
    {
        std.debug.warn("hello");
}

Please specify the license for this package

Could you please specify the license used by this package?

Assuming that you want to release under "the GPL v3 or any later version", the best way to do that would be to add this to the library header:

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

You could also, or instead, add a LICENSE file containing the text of the GPL-3. But if you only add that file, then the "or (at your option) any later version" bit won't be known. I recommend that you do both.

If this is too noisy for you, then you could also add one of these following lines to the header. (I do however recommend against doing only that - a judge might decide that this is not sufficient.)

;; License: GNU General Public License version 3, or (at your option) any later version
;; License: GNU General Public License version 3, or any later version
;; License: GNU GPL version 3, or (at your option) any later version
;; License: GPL version 3, or (at your option) any later version
;; License: GPL version 3, or any later version
;; License: GPL v3, or (at your option) any later version
;; License: GPL v3, or any later version
;; License: GPL-3+

Prefer flycheck and lsp-ui to *zig-fmt* split window

Someone on Discord gave me this code that allows flycheck to work with zig-mode:

(flycheck-define-checker zig
    "A zig syntax checker using the zig-fmt interpreter."
    :command ("zig" "fmt" (eval (buffer-file-name)))
    :error-patterns
    ((error line-start (file-name) ":" line ":" column ": error: " (message) line-end))
    :modes zig-mode)
(add-to-list 'flycheck-checkers 'zig)

And both flycheck and lsp-ui worked:

flycheck

However, zig-mode always opens *zig-fmt* split window. This is duplicate, so it's nice if we can suppress the behavior.

Thank you.

Consider more maintainers?

First of all, thanks for this awesome package! 🚀

I wonder does this package needs more maintainers? 🤔If so, I would like volunteer myself. I had this question because there were trivial issues, and PRs were left unresponsed.

I serve as the primary maintainer for emacs-dashboard and one of the maintainers for lsp-mode (focus on contributing to lsp-zig.el). I have developed over a hundred Emacs packages. I hope I am qualified to help maintain this package.

Cheers!

README makes no mention of reformatter dependency

Got an ugly error message when trying to load zig-mode:

File mode specification error: (file-error Cannot open load file Not a directory reformatter)

Turns out there is a dependency on emacs-reformatter. Only figured it out because I tried to run the tests and I noticed the script installed reformatter using elpa.

It would be helpful if the README could mention adding emacs-reformatter's reformatter.el to load-path before trying to load zig-mode.

Incorrectly keeping prefix when using fill-region?

Hey thanks for this! I start out with:

//Hey this is a really really really really really really really long line. 

And run fill-region on the line and get:

//Hey this is a really really really really really really really
long line.

The subsequent lines are incorrectly not commented.

Or another variation of it (before fill-region):

//Hey this is a really really really really really really really really really really
//long line.

And after fill-region:

//Hey this is a really really really really really really really
really really really //long line.

It doesn't preserve the comment markers in the right place.

Tangent

It would also be great if this was supported for multiline strings. Emacs does the wrong thing in zig-mode if I have:

\\Hey this is a really really really really really really really really really really
\\long line. 

And I call fill-region on that:

\\Hey this is a really really really really really really really
really really really \\long line. 

I'd hope that it preserves the string like I'd hope it preserves the comment.

Expected Behavior

In bash-mode if you do fill-region on a commented section, it fills the region keeping the comment prefix correctly.

(before fill-region)

#Hey this is a really really really really really really really really really really
#long line.

(after fill-region)

#Hey this is a really really really really really really really really
#really really long line.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.