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

Compared to 0.9, 1.0.1 does not handle re-indentation correctly #90

Closed
PetrKryslUCSD opened this issue Oct 9, 2020 · 25 comments · Fixed by #92
Closed

Compared to 0.9, 1.0.1 does not handle re-indentation correctly #90

PetrKryslUCSD opened this issue Oct 9, 2020 · 25 comments · Fixed by #92

Comments

@PetrKryslUCSD
Copy link

PetrKryslUCSD commented Oct 9, 2020

For instance, this code is not re-indented correctly when I do "select all" and "reindent":

function e1_hole_q4()

    function solve(iteration, fens, fes)
     
        # Identify the "growth" layer of elements
        node_is_act_bdry = fill(false, count(fens))
        node_is_act_bdry[lopeningn] .= true
        el_in_growth_layer = fill(false, count(fes))
        for i in 1:count(fes)
            for j in fes.conn[i]
                if node_is_act_bdry[j]
                    el_in_growth_layer[i] = true
                    break
                end
            end
        end
        
# Apply mechanical support conditions to eliminate rigid body
# displacements
u = NodalField(zeros(size(fens.xyz, 1), 2)) # displacement field
setebc!(u, lleft0n, 1, 0.0)
setebc!(u, lleft0n, 2, 0.0)
setebc!(u, lright0n, 2, 0.0)
applyebc!(u)
numberdofs!(u)
end
end

ST3 with Julia-sublime package 0.9 can do it right.

@PetrKryslUCSD
Copy link
Author

I checked the Indentation.tmPreferences files for ST versions 3 and 4: they are identical. So at the moment I have no explanation for the different behavior. I am in a conversation with the developers of ST to see if we can sort it out.

@PetrKryslUCSD
Copy link
Author

PetrKryslUCSD commented Oct 13, 2020

I was able to narrow it down quite a bit:

function f(x)
y = x^2 # comment
end

function f(x)
y = x^2 
end

In ST 4 the first definition of the function is not reindented properly. ST 3 does the job correctly.

@PetrKryslUCSD
Copy link
Author

PetrKryslUCSD commented Oct 13, 2020

It seems to me that being confused about scope could be an explanation.
Or not (consultation with @OdatNurd)....

@PetrKryslUCSD
Copy link
Author

More data: sublimehq/Packages#2550 (comment)

@PetrKryslUCSD
Copy link
Author

PetrKryslUCSD commented Oct 14, 2020

The problem is apparently in the definition of comments:

comments:
    - match: \#=
      scope: punctuation.definition.comment.number-equal-sign.julia
      push:
        - meta_scope: comment.block.number-equal-sign.julia
        - match: =\#
          scope: punctuation.definition.comment.number-equal-sign.julia
          pop: true
    - match: \#+
      scope: punctuation.definition.comment.julia
      push:
        - meta_scope: comment.line.number-sign.julia
        - match: \n
          pop: true

I replaced this with the old definition

  comments:
    - match: '#='
      push: comment-block
    - match: '#.*'
      scope: comment.line.number-sign.julia

  comment-block:
    - meta_scope: comment.block.number-sign-equals.julia
    - match: '#='
      push: comment-block
    - match: '=#'
      pop: true

and the re-indentation on ST 4 works as well as on ST3.

Edit: Actually, with the new definition re-indentation doesn't work when a block comment is present. Neither on ST 4, nor on ST3.
And, being the "old" definition, it never worked with ST3 for block comments.

@PetrKryslUCSD
Copy link
Author

It seems that @ViktorQvarfordt is the author of the comment definitions? Any ideas how to fix this properly, Viktor?

randy3k added a commit that referenced this issue Oct 14, 2020
@randy3k randy3k mentioned this issue Oct 14, 2020
@PetrKryslUCSD
Copy link
Author

Except for the issue of the block comments the proposed change makes the indentation work the same in ST 4 and ST 3.

@randy3k
Copy link
Collaborator

randy3k commented Oct 14, 2020

I always do no trust the auto-indentation feature of editors. If you want to format a document, it is better to use a code formatter, for example https://github.com/domluna/JuliaFormatter.jl

@PetrKryslUCSD
Copy link
Author

That is true, I tried that package and it works great. However, the workflow is much smoother with re-indentation integrated into the editor. And most of the times it works just fine.

@PetrKryslUCSD
Copy link
Author

By the way, I use re-indentation most often on just selections, not the entire documents. Then the use of a package to do that is much less attractive.

@randy3k
Copy link
Collaborator

randy3k commented Oct 14, 2020

I have pushed one more commit, all the comments code are ignored when applying indentation.

function f(x)
# comment
x = 1
end

function(x)
        #comment
        x = 1
end

function(x)
#=
comment 1
    comment 2
=#
x = 1
end

function(x)
        #=
        comment 1
            comment 2
        =#
        x = 1
end

becomes

function f(x)
# comment
    x = 1
end

function(x)
        #comment
    x = 1
end

function(x)
#=
comment 1
    comment 2
=#
    x = 1
end

function(x)
        #=
        comment 1
            comment 2
        =#
    x = 1
end

@PetrKryslUCSD
Copy link
Author

PetrKryslUCSD commented Oct 14, 2020

I don't know, this is what I got:

function f(x)
# comment
x = 1
end

function(x)
        #comment
x = 1
end

function(x)
#=
comment 1
    comment 2
=#
x = 1
end

function(x)
        #=
        comment 1
            comment 2
        =#
x = 1
end

Edit 10/15: I don't know what happened last time, but when I redid this whole process of installing the PR, I got this result:

function f(x)
    # comment
    x = 1
end

function(x)
    #comment
    x = 1
end

function(x)
#=
comment 1
    comment 2
    =#
    x = 1
end

function(x)
        #=
        comment 1
            comment 2
            =#
            x = 1
        end

@randy3k
Copy link
Collaborator

randy3k commented Oct 15, 2020

Did you fetch the PR?

@PetrKryslUCSD
Copy link
Author

I downloaded the PR and made a package file from it. It did not work for me.

Here's another example where the re-indentation does not work yet:

function flint_loadmesh(meshfile, nunref = 0, nref = 0)
  # Mesh file in the format of the Abaqus .inp file
  fens, fes = BEMScat.MeshingUtilities.loadmesh(meshfile)
  
  if nodesperelem(fes) == 10
    fens, fes = T10toT4(fens, fes) # Convert to linear tetrahedra
end

# The coordinates are in millimeters
fens.xyz .*= phun("mm") # The input file lists the coordinates of the nodes in millimeters
end

@randy3k
Copy link
Collaborator

randy3k commented Oct 15, 2020

It gives me

function flint_loadmesh(meshfile, nunref = 0, nref = 0)
  # Mesh file in the format of the Abaqus .inp file
  fens, fes = BEMScat.MeshingUtilities.loadmesh(meshfile)
  
  if nodesperelem(fes) == 10
    fens, fes = T10toT4(fens, fes) # Convert to linear tetrahedra
  end

# The coordinates are in millimeters
  fens.xyz .*= phun("mm") # The input file lists the coordinates of the nodes in millimeters
end

which is what I expected.

@PetrKryslUCSD
Copy link
Author

Okay, then I am perplexed.
However, it does work when I decrease indents until everything is at the leftmost column.
Then I get

function flint_loadmesh(meshfile, nunref = 0, nref = 0)
# Mesh file in the format of the Abaqus .inp file
    fens, fes = BEMScat.MeshingUtilities.loadmesh(meshfile)

    if nodesperelem(fes) == 10
        fens, fes = T10toT4(fens, fes) # Convert to linear tetrahedra
    end

# The coordinates are in millimeters
    fens.xyz .*= phun("mm") # The input file lists the coordinates of the nodes in millimeters
end

@PetrKryslUCSD
Copy link
Author

When I simply copy the code

function flint_loadmesh(meshfile, nunref = 0, nref = 0)
  # Mesh file in the format of the Abaqus .inp file
  fens, fes = BEMScat.MeshingUtilities.loadmesh(meshfile)
  
  if nodesperelem(fes) == 10
    fens, fes = T10toT4(fens, fes) # Convert to linear tetrahedra
end

# The coordinates are in millimeters
fens.xyz .*= phun("mm") # The input file lists the coordinates of the nodes in millimeters
end

and try to re-indent it, then nothing happens.

@randy3k
Copy link
Collaborator

randy3k commented Oct 15, 2020

I wonder if you have applied the PR correctly.

@PetrKryslUCSD
Copy link
Author

I downloaded the PR using Github desktop.

@PetrKryslUCSD
Copy link
Author

PetrKryslUCSD commented Oct 15, 2020

image

@PetrKryslUCSD
Copy link
Author

I checked the TMPreferences files as well. I do seem to have all your changes.

@PetrKryslUCSD
Copy link
Author

Would you like to try it out with my portable ST 4?
https://www.dropbox.com/s/c5gfx2z9xiuusem/archived-SublimeText4_portable-10-15-2020-02-42.zip?dl=0

@PetrKryslUCSD
Copy link
Author

function flint_loadmesh(meshfile, nunref = 0, nref = 0)
  # Mesh file in the format of the Abaqus .inp file
  fens, fes = BEMScat.MeshingUtilities.loadmesh(meshfile)
  
  if nodesperelem(fes) == 10
    fens, fes = T10toT4(fens, fes) # Convert to linear tetrahedra
end

# The coordinates are in millimeters
fens.xyz .*= phun("mm") # The input file lists the coordinates of the nodes in millimeters
end

Sorry to report but this still does not work correctly. When I try to re-indent, nothing happens. It stays the same. The other examples above work fine.

randy3k added a commit that referenced this issue Nov 30, 2020
@PetrKryslUCSD
Copy link
Author

#90 (comment): this is still not reindented properly.

@PetrKryslUCSD
Copy link
Author

PetrKryslUCSD commented Nov 30, 2020

@randy3k : If the above sample re-indents properly in your ST, perhaps there's something different between our setups? Perhaps another package interferes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants