Generate ctags for Ruby and Javascript - ctags

Currently I'm using this command to generate ctags:
ctags -R --languages=ruby,javascript --exclude=.git --exclude=log . $(bundle list --paths)
This works for Ruby, but not for the JavaScript. How can I fix that, so that JavaScript code will be in ctags too?

Adding --tag-relative and --sort=yes fixed the problem.
ctags --tag-relative -R --sort=yes --languages=ruby,javascript --exclude=.git --exclude=log . $(bundle list --paths)

Related

"ctags: Unknown option: --output-format" error

On macOS, getting the error while running this command:
ctags -R --output-format=json --languages=ruby --exclude=.git --exclude=log . $(bundle list --paths) -f .tags
per advice here: https://www.boost.co.nz/blog/2018/01/improving-ruby-rails-debugging-ctags
It appears to be a valid command option: https://docs.ctags.io/en/latest/output-format.html
So I'm not sure why I'm getting an error.
UPDATE:
OK, that blog article has ctags installed from HEAD formula. So I installed that version but now I get a different error:
ctags: unknown output format name supplied for "output-format=json"
I followed the same article and got the same error. The problem is the suggested command:
brew install --HEAD universal-ctags/universal-ctags/universal-ctags
This doesn't build universal-ctags with libjansson and as Masatake YAMATO suggested, libjansson is needed to use --output-format=json.
Try installing universal-ctags with the --with-jansson flag:
brew install --HEAD --with-jansson universal-ctags/universal-ctags/universal-ctags
Also, to avoid the ctags: -f option may not follow a file name error, move -f .tags before . $(bundle list --paths):
ctags -R --output-format=json --languages=ruby --exclude=.git --exclude=log -f .tags . $(bundle list --paths)
You can use json output only when you built the ctags executable with libjansson library.
If you built the ctags executable with libjansson, you will see "json" in --list-features output like:
$ universal-ctags --list-features
#NAME DESCRIPTION
iconv can convert input/output encodings
interactive accepts source code from stdin
json supports json format output
...
If you don't find "json", you must rebuild the ctags executable with libjansson library.
If you find "json", but the option, --output-format=json, doesn't work, it will be a bug. I recommend you to report it to https://github.com/universal-ctags/ctags/issues though fixing it is not promised.

Ruby gem tab completion on zsh produces "doubled rest argument definition" error?

When I hit gem push <tab>, it displays this error (regardless of whether the directory contains any .gem files):
_arguments:comparguments:325: doubled rest argument definition: *:gem:_files -g "*.gem(-.)"
_arguments:comparguments:325: doubled rest argument definition: *:gem:_files -g "*.gem(-.)"
_arguments:comparguments:325: doubled rest argument definition: *:gem:_files -g "*.gem(-.)"
I have no idea how to fix this and Google is no help. My fpath:
> echo $fpath
/Users/robenkleene/.zsh/completion
/usr/local/share/zsh/site-functions
/usr/local/Cellar/zsh/5.7/share/zsh/functions
I've tried uninstalling and re-installed Ruby via homebrew because the above "Cellar" path contains a _gem file that I believe defines this completion function, but that didn't work.
Any other ideas? Thanks!
(Also, if anyone has any suggestions of where I might file a bug report for this that would also be helpful, thanks again!)
I hacked together my own terrible solution to this but it's better than nothing.
I copied the _gem file from /usr/local/Cellar/zsh/5.7/share/zsh/functions to /Users/robenkleene/.zsh/completion and then modified the offending line (note that this only works because I have fpath=(~/.zsh/completion $fpath) in my zshrc):
- args+=( '*:gem:_files -g "*.gem(-.)"' )
+ args=( '*:gem:_files -g "*.gem(-.)"' )
So I removed the +. This seems to work, but I'd love a more elegant solution and/or any information about why (based on my Google search), I seem to be the only person experiencing this.
I'm on macOS 10.15.6 running the default zsh 5.7.1. In the default zsh gem completion I found that push is being included in a list of commands which take a remote gem name — and it shouldn't be, it only takes the path to the gem file:
$ gem push --help
Usage: gem push GEM [options]
I applied the following patch to a copy of the file higher in $fpath and it now works for me:
--- /usr/share/zsh/5.7.1/functions/_gem
+++ ~/.zsh/completion.d/_gem
## -56,7 +56,7 ##
check|cleanup|contents|dependency|list|open|pristine|rdoc|uninstall|unpack|update)
args+=( '(--all --skip)*:installed gem:->gems-local' )
;|
- fetch|install|lock|owner|push|search|yank)
+ fetch|install|lock|owner|search|yank)
args+=( '*:gem:->gems-remote' )
;|
cleanup|uninstall)
I'm not sure where to contribute this patch. 😅

Exuberant Ctags can't work fine on OSX

I want use Ctags for Lua.
Ctags doesn't support Lua, so I found a command:
ctags --langdef=MYLUA --langmap=MYLUA:.lua --regex-MYLUA="/^.*\s*function\s*(\w+):(\w+).*$/\2/f/" --regex-MYLUA="/^\s*(\w+)\s*=\s*[0-9]+.*$/\1/e/" --regex-MYLUA="/^.*\s*function\s*(\w+)\.(\w+).*$/\2/f/" --regex-MYLUA="/^.*\s*function\s*(\w+)\s*\(.*$/\1/f/" --regex-MYLUA="/^\s*(\w+)\s*=\s*\{.*$/\1/e/" --regex-MYLUA="/^\s*module\s+\"(\w+)\".*$/\1/m,module/" --regex-MYLUA="/^\s*module\s+\"[a-zA-Z0-9._]+\.(\w+)\".*$/\1/m,module/" --languages=MYLUA --excmd=number -R .
It's too long, or you can see a shorter sample only for lua functions.
ctags --langdef=MYLUA --langmap=MYLUA:.lua --regex-MYLUA="/^.*\s*function\s*(\w+)\s*\(.*$/\1/f/" --languages=MYLUA --excmd=number -R .
Both of the two works fine on Windows.
On OSX, there was no error, but the tags file is empty.
PS:I used Exuberant Ctags v5.8, not default ctags on OSX.
Here's a test Lua code for ctags.
function f1()
end
function c.f2()
end
function c:f3()
end
The exuberant ctags version that you can find at https://github.com/fishman/ctags appears to have native lua support. Have you tried that instead?
Finally, i fixed it.
'\w' can't use in this regex('\w' isn't OK, too), i don't know why. I use '[^\s:>]' instead of '\w'.
'\1' or '\2' must escape to '\\1' or '\\2', but '\s' is OK. Don't know why, too.
Now, the command change to
ctags --langdef=MYLUA --langmap=MYLUA:.lua --regex-MYLUA="/^.*\s*function\s*([^\s:.]+):([^\s:.]+).*$/\\2/f/" --regex-MYLUA="/^\s*([^\s:.]+)\s*=\s*[0-9]+.*$/\\1/e/" --regex-MYLUA="/^.*\s*function\s*([^\s:.]+)\.([^\s:.]+).*$/\\2/f/" --regex-MYLUA="/^.*\s*function\s*([^\s:.]+)\s*\(.*$/\\1/f/" --regex-MYLUA="/^\s*([^\s:.]+)\s*=\s*\{.*$/\\1/e/" --regex-MYLUA="/^\s*module\s+\"([^\s:.]+)\".*$/\\1/m,module/" --regex-MYLUA="/^\s*module\s+\"[a-zA-Z0-9._]+\.([^\s:.]+)\".*$/\\1/m,module/" --languages=MYLUA --excmd=number -R .
and this is OK.

How can I determine what the current stable version of Ruby is?

I want to write a Ruby method that does two things:
Determine what the current stable version of Ruby is. My first thought is to get the response from https://www.ruby-lang.org/en/downloads/ and use RegEx to isolate the phrase The current stable version is [x]. Is there is an API I'm not aware of?
Get the URL to download the .tar.gz of that release. For this I was thinking the same thing, get it from the output of the site URL.
I'm looking for advice about the best way to go about it, or direction if there's something in place I might use to determine my desired results.
Ruby code to fetch the download page, then parse the current version and the link URL:
html = Net::HTTP.get(URI("https://www.ruby-lang.org/en/downloads/"))
vers = html[/http.*ruby-(.*).tar.gz/,1]
link = html[/http.*ruby-.*.tar.gz/]
GitHub code: ruby-stable-version.rb
Shell code:
ruby-stable-version
If you are using rbenv you can use ruby-build to get a list of ruby versions and then grep against that.
ruby-build --definitions | tail -r | grep -x -G -m 1 '[0-9]\.[0-9].[0-9]\-*[p0-9*]*'
You can then use that within your code like so:
version = `ruby-build --definitions | tail -r | grep -x -G -m 1 '[0-9]\.[0-9].[0-9]\-*[p0-9*]*'`.strip
You can then use this value to get the download URL.
url = "http://cache.ruby-lang.org/pub/ruby/#{version[0..2]}/ruby-#{version}.tar.gz"
And then download the file:
require 'open-uri'
open("ruby-#{version}.tar.gz", 'wb') do |file|
file << open(url).read
end
Learn more about rbenv here and ruby-build here.
Another possibility would be to use the Ruby source repository. Check version.h in every branch, filter by RUBY_PATCHLEVEL > -1 (-1 is used for -dev versions), sort by RUBY_VERSION and take the latest one.
You can use:
Ruby's built-in OpenURI, and Nokogiri, to read a page, parse it, search for certain tags, extract a parameter such as a "src" or "href".
OpenURI to read the URL, or curl or wget at the command-line to retrieve the file.
Nokogiri's tutorials including showing how to use OpenURI to retrieve the page and hand it off to Nokogiri.
OpenURI's docs show how to "open" URLs and retrieve their content using read. Once you've done that, the data will be easy to save to disk using something like this for text files:
File.write('some_file', open('http://www.example.com/').read)
or for binary:
File.open('some_file', 'wb') { |fo| fo.write(open('http://www.example.com/').read) }
There are examples of using both Nokogiri and OpenURI for this all over Stack Overflow.

Prawn templates not working

I´m trying this simple script:
require 'prawn'
template_file_name = File.join(File.dirname(__FILE__), 'template.pdf')
pdf_file = Prawn::Document.new(:template => template_file_name)
pdf_file.text('Hello World')
pdf_file.render_file('output.pdf')
There is a template.pdf file in the same dir as the script but the output.pdf comes only with the Hello Wordl
Is there anything else that I should be concerned of?
Thanks
Templates were introduced only in prawn 0.10.1 as stated by Daniel Nelson here.
If you want to stamp a pdf file with another, and you are using Ubuntu, then try installing pdftk.
Go to a terminal and type this:
sudo apt-get install pdftk
Then go to the pdf directory and type:
pdftk content.pdf stamp template.pdf output final.pdf
If you want to do all this within Ruby, you can learn about: Calling shell commands from Ruby
I read about this solution in this link: http://numbers.brighterplanet.com/2011/10/06/stamp-pdfs-with-prawn-and-pdftk/

Resources