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

[Question] Use markers instead of line numbers #27

Open
marcinkunert opened this issue Feb 28, 2023 · 1 comment
Open

[Question] Use markers instead of line numbers #27

marcinkunert opened this issue Feb 28, 2023 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@marcinkunert
Copy link

Is there a way of embedding code using some kind of markers instead of line numbers?

Let's say I have this file:

import sth
import sth not important

fun myFun() {
 stuff here
 stuff here
}

I've embedded the myFun() part: L4-L7

fun myFun() {
 stuff here
 stuff here
}

Afterward I've noticed one of the imports is not important, so I delete it from the code base,

import sth

fun myFun() {
 stuff here
 stuff here
}

but forget to update the embedded line numbers, so the embedded part looks like this:

 stuff here
 stuff here
}

I'm aware that instead of pointing to a branch, I can point to a commit/permalink, which won't change. But this is also a disadvantage, since the code samples would show something outdated.

I was thinking if there is a way to embed code using some kind of markers. I've tried googling it, but no luck so far. Maybe you could point me to something useful.

@yusanshi
Copy link
Owner

The scene you describe is interesting. But sorry I can't find an elegant way to do it after googling either.

I believe there should be roughly two ways to implement the feature:

  • on the script side: specifing the contents of the start line and end line, instead of the line numbers. Say using the regex: start=fun myFun\(\) \{\n, end= stuff here\n\}.
  • on the code side: changing the original code by adding some special tokens in comments. For example,
// emgithub: start-next-line
fun myFun() { // or, emgithub: start-this-line
 stuff here
 stuff here
} // or, emgithub: end-this-line
// emgithub: end-last-line

Personally I prefer the second way. The first way may encounter some problems, say if there are multiple lines with the same contents. The second way is more precise in locating code, although we have to pollute the original code.

However both of them are somewhat dirty and may not be implemented in the main repo. You can try forking the repo and implement it to fit your specific needs.

Anyway I'll mark this as help-wanted. In case someone come up with an elegant way, we can do it in the main repo.

@yusanshi yusanshi added the help wanted Extra attention is needed label Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants