Git Product home page Git Product logo

julia-emacs's Introduction

julia-mode

MELPA Build Status

Emacs major mode for the Julia programming language.

Installation

Installing from MELPA

Unless you want to develop this package, it is recommended that you use it from MELPA:

  1. Enable the MELPA repository.

  2. Enable the package by adding these lines to to your Emacs init file, e.g., ~/.emacs:

(package-install 'julia-mode)
(require 'julia-mode)

Installing from Source

To get the latest version of julia-mode, clone this repository and then use:

(add-to-list 'load-path "<path-to-julia-mode>")
(require 'julia-mode)

Contributing

Contributions are welcome, in the form of pull requests.

We do our best to provide feedback within 2 weeks. Feel free bump the PR thread with a comment after that.

Submitting Pull Requests

  • Do add unit tests whenever possible. Consider breaking functions into an interface and a backend function for convenient testing.

  • Do add a short summary in the Unreleased section of the CHANGELOG.

  • Do use the rx macro (S-expressions) whenever rewriting regular expressions or introducing new ones. This keeps the code much more readable.

Working With Tests

It's easy to add new ERT tests to the julia-mode test suite.

You only need to prepare a new ert-deftest definition in julia-mode-tests.el.

You can run the test suite from the command line with:

emacs -batch -L . -l ert -l julia-mode-tests.el -f  ert-run-tests-batch-and-exit

julia-emacs's People

Contributors

dfannius avatar elzair avatar emmt avatar gcv avatar haffner avatar jamii avatar jeffbezanson avatar jiahao avatar justbur avatar li1 avatar martenlienen avatar non-jedi avatar nverno avatar ralphas avatar recri avatar rfourquet avatar ronisbr avatar rsrock avatar rtpg avatar simonbyrne avatar sje30 avatar stefankarpinski avatar stevengj avatar timholy avatar tpapp avatar volker-weissmann avatar westleyargentum avatar wilfred avatar yuhan0 avatar yuyichao 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

julia-emacs's Issues

Syntax Highlight

I'm using this mode with the default Emacs theme and it doesn't highlight variables when performing assignments. Is this behavior intended?

For example:
x = 2

Shouldn't x have be highlighted?

Improve parsing of quoted symbols

For example I take file julia base client.jl. Please have a look at line 185:

    occursin("\"`\"", msg) && return :cmd

In case of GRAVE ACCENT symbol quoted with escaped quotes further highlighting getting failed.

Here is screenshot for convenience
screenshot from 2018-08-14 17-48-50

My custom theme fails to highlight the variable names

Hello,
I usually use a custom theme where the variable names are highlighted in orange. I do it by putting the command '(font-lock-variable-name-face ((t (:foreground "orange red")))) in my custom-theme.el file and it works when I write python code. However, it apparently fails whit julia-mode. Do you have any suggestions?
Thanks a lot.

add completion-at-point-functions support for completing Julia keywords

Ref JuliaLang/julia#13799

ESS-Julia part has a mode called ess-julia-mode. It is derived from julia-mode. This seems from Julia. ESS-Julia support completing objects with company-ess-julia-objects for company-mode. Emacs has default completion support with completion-at-point-functions. It can be used by company-mode with backend company-capf. I hope julia-mode can complete Julia keywords with a function which add to completion-at-point-functions.

(add-hook 'completion-at-point-functions 'julia-complete-keywords-function)

Use completion-at-point for latexsub instead of overriding TAB keybinding

This would integrate nicely with e.g. company and would generally make this package a better emacs citizen. I have some custom stuff bound to TAB in my config having to do with company completion, and the hacks to make latexsub work as well aren't very nice.

The implementation is to write julia-latexsub-at-point-function and push it to completion-at-point-functions.

Are there any objections to this?

Improve highlighting of quoted symbols

Ref JuliaLang/julia#9247

I think it would make sense for quoted symbols to use constant-face by default; they are constants after all.

Also quoted-symbol-face seems not to work right at the beginning of a line. This is definitely a pretty rare case though.

Indentation after import/export

Ref JuliaLang/julia#15197

julia-mode.el does not indent after import/export according to how the source is indented. For example, it will not indent the following code this way.

import ..LinAlg: BlasFloat, Char, BlasInt, LAPACKException,
    DimensionMismatch, SingularException, PosDefException, chkstride1, checksquare

Specifically, there is no indentation on the second line

Plans for a release?

Hello,

I'd like to add julia-mode to Guix. A Guix package is typically
defined using the last released version (though an arbitrary commit
can be used if necessary). Looking through the repo history, the
version was set to 0.3 in 6105b93 (Header improvements to conform to
MELPA's standards., 2014-08-12) and has not been updated since.

Are there any plans to tag a release?

Thanks.

`fill-paragraph` wraps too much

When writing multiline strings I'd like to use fill-paragraph (M-q) to make line feeds where needed.

Example:

"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis facilisis mollis erat eget iaculis. 
"""
f(x) = 1

hitting M-q produces

""" Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis
facilisis mollis erat eget iaculis.  """ f(x) = 1

This means that currently my docstrings are bounded by newlines as that stops M-q from line-wrapping the following code too.

[Request] Better navigation in a julia buffer.

Right now in a julia-mode buffer neither forward-paragraph nor forward-sexp (and their backward equivalents) understand julia syntax to move between function definitions and control-flow code blocks. For example, the default python-mode offers this.

(\)(2, 4) upsets auto-indent

The following

(\)(2, 4)

breaks auto-indent on subsequent lines.

The following, does not

\(2, 4)

I got julia-mode.el from elpa. But, the file is identical to the master branch here, except for a comment.

Tab indentation fails

Error message when indenting code by pressing Tab is Symbol's function definition is void: looking-at-p.

This is the same problem as issue #16, however I'm not on OS X but on a Linux server where I cannot easily upgrade emacs from version 22.3.1 - is there a workaround possible?

julia-mode and org html export with background

When html-exporting this Org mode example.org (with C-c C-e h o):

#+HTML_HEAD_EXTRA: <style type="text/css"> blockquote {background:#EEEEEE; padding: 3px 13px}    </style>
#+HTML_HEAD_EXTRA: <style type="text/css"> pre {background:#EEEEEE; padding: 3px 13px}    </style>

Some text...

#+BEGIN_EXAMPLE
:: or <: ?
#+END_EXAMPLE

#+BEGIN_SRC julia 
abstract type A end
struct S <: A
   x::T
end
#+END_SRC

I get this:
julia-mode-problem

I think that there is a problem in the way the "::" and "<:" char sequences are processed, in julia-mode.el one can read:

(defconst julia-font-lock-keywords
  (list
   ;; Ensure :: and <: aren't highlighted, so we don't confuse ::Foo with :foo.
   ;; (in Emacs, keywords don't overlap).
   (cons (rx (or "::" "<:")) ''default)
   ...

If I comment this line:

   ;; (cons (rx (or "::" "<:")) ''default) 

and export again example.org with Org, I get now:
julia-mode-ok
which is fine.

Commenting the line is quite brutal and certainly has side effect.
Sure you will find a more elegant solution :-)

Use SMIE for more structured editing features

Ref JuliaLang/julia#9889

Octave-mode uses it, and it offers some nice features:

  • When use place point on an "end", the corresponding block beginning (e.g., "if") is highlighted like a matching parenthesis.
  • When you do forward-sexp starting at an expression (e.g., if...end), it understands enough to skip the entire expression, like it should, not just the next symbol.
  • You can also easily select/delete/copy entire expressions, e.g., whole loops/blocks/function definitions.
  • Things like outline/hide-show modes will work better, too, probably.

wrong indent position

In the code excerpt that follows, when I hit TAB on the line marked with the comment, the line jumps all the way to the left margin instead of the correct indent position. Weirdly, this appears to be a minimal example in the sense that if I delete a random line here or there, the problem goes away. This is for emacs version 24.3.1 running under Windows 10 (64-bit). This is Julia mode version 0.3, which I just downloaded a couple of days ago. The code (not this excerpt, but the original version before I tried to make a minimal example) loads and compiles in Julia 0.4.6, so the problem isn't being caused by a stray parenthesis or comma.

function maintimestepper()
    for tind = startstep + 1 : ntimevals

        if params.verbosity >= 1
            if params.verbosity >= 3
                println(" -----------------------------------------------------")
            end
            println("begin timestep loop tind = ", tind, " with deltat = ", deltat)
        end


        for i = 1 : ndispbc
            ubc[alldispbc[i].node, alldispbc[i].dim] = 
                curbcweight * alldispbc[i].val[tind] + 
                prevbcweight * alldispbc[i].val[tind-1]
        end
        

        
        scrap, uoffset = getinitxuoffset_for_tsm(statehist, tind, timevals, 
                                                 nnode, 
                                                 spacedim, 
                                                 maprelabs, 
                                                 mapabsrel,
                                                 massmat,
                                                 tsm)
        
        


        if tind == 2
            oldtimeval_h = timevals[1]
            oldubc = zeros(nnode, spacedim)
            for i = 1 : ndispbc
                oldubc[alldispbc[i].node, alldispbc[i].dim] = 
                    alldispbc[i].val[1] 
            end



            olduoffset = zeros(nnode * spacedim)
            w = zeros(nis1)
            s = zeros(nis1)
            fac = params.initsw
            s[1 : spacedim + 1 : end] += sqrt(2.0) * fac
            s[2 : spacedim + 1 : end] += fac
            w[1 : spacedim + 1 : end] =  sqrt(2.0) * (mu / fac)
            w[2 : spacedim + 1 : end] -= mu / fac
            y = mu / fac * ones(ni)
            f_handle = F_Handle(f_handle0, oldubc, uoffset, mass_scaling(deltat,tsm))
            x = shrink(f_handle, zeros(nx), 1.0 - mu)
            ci_handle = CI_Handle(ci_handle0, ubc, timevals[1])
            extrcon = extract_contact(ci_handle)
            contactrhs = contact_fn_val(ci_handle)
            tvar, pivar = init_tvar_pivar(extrcon, 
                                          contactrhs, 
                                          mu,
                                          x, 
                                          params.bigM)
            z = mu ./ (extrcon * x + tvar * ones(ncb) - contactrhs)



        else
            oldtimeval_h = prevbcweight * timevals[tind - 2] + 
                curbcweight * timevals[tind - 1]
            for i = 1 : ndispbc
                oldubc[alldispbc[i].node, alldispbc[i].dim] = 
                    curbcweight * alldispbc[i].val[tind-1] + 
                    prevbcweight * alldispbc[i].val[tind-2]
            end

            scrap, olduoffset = getinitxuoffset_for_tsm(statehist, tind - 1, 
                                                        timevals, 
                                                        spacedim, 
                                                        nnode, 
                                                        maprelabs, 
                                                        mapabsrel,
                                                        massmat,
                                                        tsm)
            x = xi_save[:,tind-1]
            s = si_save[:,tind-1]
            w = wi_save[:,tind-1]
            y = yi_save[:,tind-1]
            z = zi_save[:,tind-1]
            pivar = pivari_save[tind-1]
            tvar = tvari_save[tind-1]
        end



        for step_bc = 1 : params.init_nstep_bc
            checkstopiteration(stopiterationtime)

            timelambda = Float64(step_bc) / Float64(params.init_nstep_bc)
            midubc = (1.0 - timelambda) * oldubc + timelambda * ubc
            midtimeval_h = (1.0 - timelambda) * oldtimeval_h + timelambda * timeval_h
            midoffset = (1.0 - timelambda) * olduoffset +
                timelambda * uoffset
            f_handle = F_Handle(f_handle0, midubc, 
                                midoffset, mass_scaling(deltat, tsm))
            ci_handle = CI_Handle(ci_handle0, midubc, midtimeval_h)
            extrcon = extract_contact(ci_handle)
            nlipkkt = NlipKKT(f_handle, h_handle, ci_handle, mu, params)
            x, s, w, y, z, tvara, pivara = splitvec(catvar, 
                                                    [nx, nis1, nis1, ni, ncb, 1, 1])

            tvar, pivar = init_tvar_pivar(extrcon, contactrhs, x, mu, params.bigM)
            catvar = vcat(x, s, w, y, z, tvar, pivar)
            newtonstep = -jac \ bfval
            bfval, jac = nlip_kkt_(nlipkkt, catvar, 1)
            alpha, alphareason = linesearch(catvar, newtonstep, 
                                            f_handle, h_handle, ci_handle, mu,
                                            params)
            catvar += alpha * newtonstep
            if params.verbosity >= 3
                println(" alpha = ",alpha, " timelambda = ", timelambda,
                        " norm(bfval) = ", norm(bfval))
            end
        end
        # hitting tab here causes x to jump to the left margin
        x, s, w, y, z, tvara, pivara = splitvec(catvar, 
                                                [nx, nis1, nis1, ni, ncb, 1, 1])
    end
end

Looks for julia-latexsubs in directory of file in current buffer

On julia-mode 20191128.1452, if (for example) I open the file
/home/username/.julia/dev/MyPackage/src/foo.jl
I get the following error:

File mode specification error: (file-missing Cannot open load file No such file or directory /home/myusername/.julia/dev/MyPackage/src/julia-latexsubs)

After this, there is no syntax highlighting or other expected functionality.

This is on Cygwin. I could try Linux later if no one can reproduce on Linux.

julia-mode breaks prettify-symbols for auctex

When julia-mode is loaded during init, prettify-symbols-mode is broken for auctex. I can reproduce this by calling emacs -q --load "init-bug.el", where init-bug.el is:

(package-initialize)
(global-prettify-symbols-mode t)
(require 'julia-mode)

Then, I C-x C-f mwe.tex where mwe.tex is:

\documentclass{article}
\begin{document}    
\[
\alpha \times \beta 
\]
\end{document}

What you should see is the unicode characters replacing alpha, times and beta, but with that init file, no prettifying occurs. If you remove the (require 'julia-mode) line from the init file, prettifying works just fine. I believe the issue is the call to (require 'latex nil t) on line 836 of julia-mode.el. That appears to load auctex outside of when it doesn't expect to be loaded, which sets the prettify alist to nil. I believe (thought am not totally sure) that you can achieve the same test without loading auctex by using (featurep 'latex) in place of that require call.

Emacs version: 26.1
julia-mode version: 20191225.858

adding binary operator special characters

Hi,
could we make \xor a synonym for \veebar ?
also, maybe consider the following
\bigcap \and => map to 'and' function
\bigcup \or => map to 'or' function

I actually tried to do a pull requesst for this but couldn't due to denied permission when i tried to push my changes.
do you need an account to work on julia emacs mode ?

RFC: drop support for Emacs 23

Supporting only Emacs 24 and above would have the following advantages:

  1. simpler CI setup (cf #84)

  2. ability to use cl-lib (instead of cl as we currently do, cf #60).

Please comment on this, especially if you need Emacs 23. As developers are usually on the bleeding edge, it is easy to forget about users operating in legacy environments.

Some data:

  • Emacs 24.1 was released on 2012-06-10,

  • the oldest Ubuntu LTS supporting Emacs 24 is Trusty (2014-04), other distributions have a similar timeline

Highlight of triple quote string with escaped quote

The triple quote string is not highlighted correctly if there's another triple quote in the string that has only the first quote escaped.

Screenshot,
spectacle x15522
The first line is highlighted correctly but the second one not.

Simple tab-indenting fails

I'm running emacs with julia-mode in terminal on OS X 10.10. Tab-indenting fails with "Symbol's function definition is void: looking-at-p". Here is a screen shot of a working example:

indent-fail

Edit docstrings with markdown-mode

Would be really nice if julia-mode provided ability to edit docstrings using
markdown-mode. Not an elisp guy, and still a relatively new emacs user, so I'm
not sure exactly how this would work, but I thought I'd throw the suggestion out
there.

Maybe if I get some time, I'll take a look at how org-mode does it with src
blocks and see if I can duplicate that in julia-mode.

Provide more highlight options

First of all, thanks for this amazing package! The support of Julia in Emacs is pretty good :)

However, I think there is a point that can be improved. For example, take a look at the following figure. To the left, there is a .jl file opened in Emacs, whereas, to the right, there is the same file opened in Vim.

fig

Notice that Julia mode in Vim has many more highlight options compared to Emacs. It highlights operation symbols like +, -, = and also literals. I think it is a little bit better.

Question: is it possible to add those options in Emacs?

volunteers needed for reviewing PRs

I would like to aim for faster turnaround times for PRs submitted to this repository. I am always happy to review, but since I am hardly an Emacs Lisp expert, I would appreciate if others could help out.

I am not comfortable with pinging people without making sure they are OK with it. So if you have some Emacs Lisp experience and would be willing to help out, please respond here.

Please do this even if you are a maintainer already with commit access, it is unclear to me who is active from a rather long list.

add collaborators?

Many PRs for this repo get no attention or very delayed feedback.

Please consider adding volunteers who are active users of this code (ie Emacs & Julia) and would be willing to contribute (I would be happy to do it, I am sure there are other past contributors who would join).

Indentation inside parenthesis

Ref JuliaLang/julia#8971
Ref JuliaLang/julia#11498

A few cases right now.

function1(a, b, c
          d, e, f)
function2(
          a, b, c
          d, e, f)
for i in Float64[1, 2, 3, 4
                 5, 6, 7, 8]
end
for i in Float64[
                 1, 2, 3, 4
                 5, 6, 7, 8]
end
a = function3(function ()
              return 1
              end)
a = function4(
              function ()
              return 1
              end)

Some proposed changes

function1(a, b, c
          d, e, f)
# Or
function1(a, b, c
    d, e, f)
function2(
    a, b, c
    d, e, f)
for i in Float64[1, 2, 3, 4
                 5, 6, 7, 8]
end
# Or
for i in Float64[1, 2, 3, 4
        5, 6, 7, 8]
end
for i in Float64[
        1, 2, 3, 4
        5, 6, 7, 8]
end
a = function3(function ()
                    return 1
                end)
a = function4(
                function ()
                    return 1
                end)

beginning-/end-of-defun should move out of the *top-level* construct

The Emacs manual is quite clear about this:

These commands move point or set up the region based on top-level
major definitions, also called “defuns”.

(emacs) Moving by Defuns

In interactive programming jupyter-eval-defun (or whatever method
you use) should eval the current top-level construct. This may be a
function but could also be a type definition or whatever.
*-eval-defun relies on beginning-/end-of-defun.

Is this package in elpa?

My emacs list-packages output includes:

julia-mode is an installed package.

     Status: Installed in `~/.emacs.d/elpa/julia-mode-20160327.225/' (unsigned).
    Archive: n/a
    Version: 20160327.225
    Summary: Major mode for editing Julia source code
   Homepage: https://github.com/JuliaLang/julia
   Keywords: languages 
    Other versions: 20160327.225 (melpa).

I noticed the homepage is not this repo (points to main julia repo).

Are they different packages?
Is there a reason to prefer one over the other?

multi-line lambda not indented correctly as function parameter

Expected Got

lines=[]
Channel(c->begin
        for l in lines
        for w in split(l)
        put!(c, w)
        end
        @show l
        end
        end)

Got Expected

lines=[]
Channel(c->begin
        for l in lines
            for w in split(l)
                put!(c, w)
            end
            @show l
        end
        end)

Do mind that I'm asking for the lambda code to be indented the same as its declaration (at c parameter). This is why the last two end are aligned.

This same-indenting may not be consistent, but I don't think so. If it is, I'll change the example.

parenthesis matching and indentation of `\)`

(\)
 1
 (:\)
  1

The (\) and (:\) are both complete expressions and it shouldn't indent the line afterward. In general I think \ doesn't escape anything outside string in julia.

Indentation for large code blocks

There's currently a limit of lines/statement per code blocks that can be indented correctly. It is a pretty large limit but can be seen when indenting a large function (e.g. some in inference.jl).

Reproduce with

function f()
    g = begin
        function ()
            return begin
                1
            end
        end
    end
    # repeat the `g =` block above ~150 times.
end

Ref JuliaLang/julia#9831 (the original issue of arguments/list is already fixed)

structs are not indented

I'm using emacs-26.2-2.fc31.x86_64 with julia-mode-20191128.1452 in melpa. I can get it to indent functions, but it doesn't indent structs at all. Didn't earlier versions indent structs?

struct Example
x::Float64 # should be indented when I hit tab but it doesn't work
end

indentation fails with the \ function

This comes from the current "deprecated.jl" file:

_promote_array_type(::typeof(\), ::Type{<:Integer}, ::Type{<:Integer}, T::Type) = T
                    this_line_is_not_correctly_indented()

Keyword type --> struct

keyword "type" is now (julia v. 0.6) deprecated, substituted by "struct"

please at least add keyword "struct"

also "immutable" is deprecated

Support for end-of / beginning-of-defun functions

it would be nice to have support for function movement functions. This would have the
added benefit of allowing better interaction with ESS julia shell, eg. ess-eval-function (see emacs-ess/ESS#777).

I don't know if it would be better navigate to nested function start/end or just outer functions?
Examples of functions that would be nice to support

module Test

function test(a::Int64)
    if a == 1
        a = 2
    elseif a == 2
        a = 3
    end
    @show a
end

f1() = 1

f2(x
  ) =
      x +
      1

f3(x, y) = x +
     y
f4(x, y)::Int16 =
    x - y

f5(x, y, z...) = x * y +
    length(z)
                
f6(x, y) = x +
    y, x-y

function my_factorial(x)
    
    function fact(n)
        if (n == 0)
            return 1
        else
            return n * fact(n - 1)
        end
    end
    
    return fact(x)
end

end

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.