Highlighting Github README.md format in Sublime Text 2 - sublimetext

I have got README file and I want Sublime to highlight only some pieces of code idented by some "tag", for example:
Here is an example of usage
# This should be highlighted
```ruby
superhero = Superhero.new
superhero.make_world_better
```
or with [code lang=ruby] or whatever

Lazy answer
(for independent fast learners)
Install package control for
sublime-text.
Once you restarted sublime-text, see "Fast Answer".
Fast answer
(for intermediate to advanced sublime-text users)
Ctrl+Shift+P and Package Control: Install Package,
then install Knockdown.
That's it, now you have a Set Syntax: Markdown (Github flavored)
option right at the reach of your fingertips.
Elaborate answer
(powerless to powerfull)
- Installing Package Control
Open sublime-text.
[If you need this functionality available when you edit files on a directory
owned by root or www-data ( i.e. /var/www/ ) you may want to open sublime with admin
privileges using gksu sublime or similar and repeat every step]
Activate sublime's console by pressing ctr+`
[That is CONTROL key plus GRAVE ACCENT key (usually above the TAB key)]
Copy-paste one of the following options to sublime console's prompt.
(and press enter):
If sublime-text 2:
import urllib2,os,hashlib; h = '7183a2d3e96f11eeadd761d777e62404' + 'e330c659d4bb41d3bdf022e94cab3cd0'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); os.makedirs( ipp ) if not os.path.exists(ipp) else None; urllib2.install_opener( urllib2.build_opener( urllib2.ProxyHandler()) ); by = urllib2.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); open( os.path.join( ipp, pf), 'wb' ).write(by) if dh == h else None; print('Error validating download (got %s instead of %s), please try manual install' % (dh, h) if dh != h else 'Please restart Sublime Text to finish installation')
If sublime-text 3:
import urllib.request,os,hashlib; h = '7183a2d3e96f11eeadd761d777e62404' + 'e330c659d4bb41d3bdf022e94cab3cd0'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)
Close sublime when the console prints back a message saying "Please restart Sublime Text to finish installation" (usually almost instantaneous). Open sublime-text again.
Once you restarted sublime-text, the rest is easy, see "Fast Answer" (above), or read on.
About using Package Control
What you just installed adds a new bunch of commands to your Palette and opens the door to a wonderful world of community contributed plugins; a way to extend sublime's functionality by other people or by yourself! (share your code!).
Now lets use it to install knockdown.
You can access Package Controll simply by pressing ctr+shift+P, and typing Package Control, pc, pack (or anything similar thanks to the fuzzy search feature of the command palette), in this case search the right command by writing Package Control: Install Package (or just pi).
(If something goes wrong you can always Remove Package).
To see all the available packages just enter or click on it. Sublime will search for all the registered packages and will even check and show for you only the ones that are compatible with your version of sublime-text, you'll have to wait a few seconds.
(or less than a second, depending on your internet+computer latency+speed).
Now search for and select knockdown.
After you hit Enter or click on it it will take a brief moment to install.
That's it, it just works.
## - How to use it you ask?
To activate this highlighting in the current loaded buffer:
(lets say "the open file")
Inside sublime-text and with a .md file opened, press ctr+shift+P again.
Search for Set Syntax: Markdown (Github Flavored) and enter or click on it.
IF you want to activate for all .md files (that's a big IF)
On current version (Latest Sublime Text 2 releases & any ver 3 release):
Navigate through the following menus: View -> Syntax -> Open all with current extension as... ->[your syntax choice].
On previous versions of sublime:
Go to a Packages/User, create (or edit) a .sublime-settings file
named after the Syntax where you want to add the extensions,
Markdown (Github Flavored).sublime-settings in your case, then
write there something like this:
{
"extensions":
[
"md"
]
}
And then restart Sublime Text
... pics, else it shant have come to pass:
(it totally works! here's the evidence)
presto!
You just took one further step to be a sublime-text master, I hope my answer helped you

Your example is describing Markdown structured text
Try
1) Save file with .md extension
2) View -> Syntax -> Open all with current extension -> Markdown

Related

Copy paste from irb excluding prompt at start of line?

When copy/pasting from irb to an .rb file the start of each line should be removed.
A short example, say you copy this from irb:
irb(main):049:1* def thing(x, y)
irb(main):050:1* out = x * y
irb(main):051:1* puts out
irb(main):052:0> end
=> :thing
irb(main):053:0> thing(2, 3)
6
=> nil
it would be handy to paste only this:
def thing(x, y)
out = x * y
puts out
end
=> :thing
thing(2, 3)
6
=> nil
Is there any special copy/paste command to achieve this, either already built into irb, available through some sort of extension, or even operating system shortcut (running macOS)?
What I tried
A regular expression could be used to remove the prompts, but it's not ideal since it assumes the paste will be into a text editor with find and replace with regex.
Although completely unrelated to rails, Google Docs, has a convention of cmd + shift + paste to 'paste without formatting'. I'm after something similar for irb like 'copy without prompt'.
Note: I'm using the macOS terminal (zsh)
You can hold the ⌥ Option key and drag for a rectangular selection:
You can also customize IRB's prompt. Here's an example of the built-in --noprompt option which provides a blank prompt:

Cmder wrong colors using Windows Terminal

I am trying to use Cmder in Windows Terminal. I tried following this guide, and I did everything as it says.
However, there is a small issue. No matter what I do, the prompt background colour does not change, it stays black.
I couldn't figure out the issue. Any suggestions?
In the comments section of the same article
I ran into this issue as well and was able to get it working. In your
"%cmder_root%\config" directory, create a file called "my_prompt.lua"
and add the following to it:
function my_prompt_filter()
cwd = clink.get_cwd()
prompt = "\x1b[1;32;49m{cwd} {git}{hg}{svn} \n\x1b[1;39;49m{lamb} \x1b[0m"
new_value = string.gsub(prompt, "{cwd}", cwd)
clink.prompt.value = string.gsub(new_value, "{lamb}", "λ")
end
clink.prompt.register_filter(my_prompt_filter, 1)
Kudos to Eric Grandt
#AMagyar 's answer is great, except that if you use conda, pyenv or other virtual environments, that information would be omitted (when it should be (base) λ, you will get λ). Instead, you can create my_prompt.lua as something like:
function my_prompt_filter()
local prompt = clink.prompt.value
prompt = string.gsub(prompt, '^\x1b%[1;32;40m', '\x1b[1;32;49m')
prompt = string.gsub(prompt, '\n\x1b%[1;39;40m', '\n\x1b[1;39;49m')
clink.prompt.value = prompt
end
clink.prompt.register_filter(my_prompt_filter, 1)
Everything is settled.
What controls the terminal text & background color?
In function set_prompt_filter in %cmder_root%\vender\clink.lua, you may read lines like:
local cmder_prompt = "\x1b[1;32;40m{cwd} {git}{hg}{svn} \n\x1b[1;39;40m{lamb} \x1b[0m"
This is the prototype of cmder prompts. The {cwd}, {git}, {lamb}, etc, are to be substituted with the actual content later on. The \x1b[1;32;40m is the ANSI escape sequence that controls the color of following text. 32 means green text color, 40 means black background color, 39 means default text color, and 49 means default background color.
Why was pyenv/conda environment omitted?
Also in function set_prompt_filter in %cmder_root%\vender\clink.lua, you may find how cmder added the information of virtual environments into {lamb} (or more specifically, prompts with () or []). So either you have to retrieve that information from the original prompt, or simply just replace the color codes, as in this answer.

Updating the tab/file status after saving in a Sublime Text Plugin

This may be an old bug; I found this report. I'm using Sublime 3 but I think this code also works on 2.
When I call self.view.run_command('save') within a plugin, the save does happen -- I can type the file in a console window and see the results. The dirty flag seems to get cleared. But the tab for the file contains a dot rather than an x, indicating the file hasn't been saved. And sure enough, if you try to close it, it asks if you want to save the file.
Is there any way to refresh the file window so it recognizes that the file has been saved?
Here's my plugin code: (This is my first plugin so please excuse obvious style issues)
# Sublime Text plugin to insert output in the OUTPUT_SHOULD_BE comment
# Bind to key with:
# { "keys": ["f12"], "command": "insert_output" },
import sublime, sublime_plugin, pprint, os, re
class InsertOutputCommand(sublime_plugin.TextCommand):
def run(self, edit):
outfile = self.view.file_name().rsplit('.')[0] + ".out"
if not os.path.exists(outfile):
sublime.error_message("Not Found: " + outfile)
return
out_data = open(outfile).read().strip()
region = self.view.find(r"/\* OUTPUT_SHOULD_BE\n", 0)
if region:
self.view.insert(edit, region.end(), out_data)
self.view.run_command('save')
self.view.window().focus_view(self.view)
else:
sublime.error_message("Not Found: OUTPUT_SHOULD_BE")
I'm sure this is probably a terrible hack, but it works:
self.view.run_command("save")
# Refresh the buffer and clear the dirty flag:
sublime.set_timeout(lambda: self.view.run_command("revert"), 10)
The revert command, which must be delayed in order to work, simply brings back whatever is stored in the file. Since the file was successfully saved on disk, this is just the same file that we already see on the screen. In the process, the dirty flag is cleared and the dot on the file tab becomes an x.
Feels very hacky to me and I'd love a more proper solution. But at least it works, ugly or not.

pandoc document conversion failed with error 43 : pdflatex: The memory dump file could not be found

RStudio : 0.98.994
OS: Microsoft Windows 7 Ultimate Edition, 64-bit Service Pack 1
MiKTeX: 2.9.4503
Hi,
I get the following error when I try to knit a PDF document.
pandoc.exe: Error producing PDF from TeX source.
This is pdfTeX, Version 3.1415926-1.40.11 (MiKTeX 2.9)
pdflatex: The memory dump file could not be found.
pdflatex: Data: pdflatex.fmt
I also tried devtools::install_github('rstudio/rmarkdown') but was still getting an error when I added 'fig.align='center' to a ggplot2 plot in my document. It would work as HTML, but not as PDF.
After seeing isomorphismes's post I clicked on the gear symbol next to the knit PDF button, then under the advanced tab I changed the LaTeX Engine to xelatex. After that I no longer received the error message and my PDF document was created without problems.
Thank you.
I found the answer here: http://rmarkdown.rstudio.com/tufte_handout_format.html#comment-1582377678
The problem is that you need to add \usepackage[utf8]{inputnc} to the preamble of the tufte-handout.tex file in the rmarkdown package.
This was fixed here: https://github.com/rstudio/rmarkdown/commit/484d5b8e903e0e0c75c82f707efa35f9fd9a52b0
To update your rmarkdown package, you can use directly in the RStudio command line
devtools::install_github("rstudio/rmarkdown")
None of the above worked for me when knitting to PDF (and I wanted to keep the scientific notation). The problem was that latex code was generated that included "\times" without the necessary bracketing by $. In the markdown I simply bracketed the inline R code with $'s, like so:
$p = `r signif(cor.HF$p.value, 2)`$
Voila!
happy to share with you my solution.
---
title: "Untitled"
author: "-----"
date: "21/6/2017"
output:
pdf_document:
latex_engine: xelatex
---
I was able to fix it in my case. I experienced that error when generate PDF from Rmd if I added float values into a text that R tried to display as a scientific notation. For example, instead of "520274.72" it tried to add text "5.2027472 e10-5" which leads to latex code \textbf{5.2027472\times 10\^{}{5}} that was not compiling. I fixed it by wrapping it with format(....,scientific=FALSE).
replace
r round(txn_pd,2)
with
r format(round(txn_pd,2),scientific=FALSE)
I had the same problem and devtools::install_github('rstudio/rmarkdown') didn't work for me. I needed to
rmarkdown::render('in.md',
output_format=pdf_document(latex_engine='xelatex')
)
with the novel command (use xelatex) on its own line.
I encountered this problem while I was trying to add an in-line r code r test1$p.value, which is a very small p-value from t test. The error information is as following:
> ! Missing $ inserted.
> <inserted text>
> $
>l.147 9.0044314\times
>
>pandoc: Error producing PDF
>Error: pandoc document conversion failed with error 43
>Execution halted
I think the problem is the pdflatex engine has a trouble in displaying the small p-value in exponential notation.
I solved the problem by clicking on the gear symbol next to the knit button, then under output options, advanced tab I changed the LaTeX Engine to lualatex, or you can just report the p-value as p < 0.001.
If you are using inline values from your R code which are in the scientific format (too small or too big), format them like:
replace r x
with r format(x, digits=n) where n is whatever.
for me it was because on my headers I was putting + signs. For example gene + treatment. This errors but when I removed it, it works.
In my case it was solved simply by editing the author field in:
---
title: "Document Title"
author: '-----'
date: "21-03-2017"
output: pdf_document
---
the default '-----' would yield the error, but replacing it with anything (for example 'Juan') solved the issue.
I just ran into this problem and already solved it. I didn't use any code as other people did in their posts.
I will assume that you have installed all these basic stuff: R, RStudio, the rmarkdown package, the knitr package, and the MikTex basic installation (I know this is very basic, but I want those first timers know that you need these stuff to make this happen).
If you run into this problem, go to R GUI, upgrade the rmarkdown package and it should work then. Note that if you change the LaTeX Engine to xelatex as the poster of the highest vote did, it may not work for you, at least it did not for me. I leave my latex engine as it is (pdflatex).
I had a similar issue. My solution was to remove the "leading" period in the YAML title argument:
Does not work:
---
title: “1. Title”
output: pdf_document
---
output file: example.knit.md
! Argument of \reserved#a has an extra }.
\par l.79 \end{enumerate}}
pandoc: Error producing PDF Error: pandoc document conversion failed
with error 43 Execution halted
Works:
---
title: “1 Title”
output: pdf_document
---
I did try to use the xelatex engine but still, I got the error that xetex.def is not found. This is another to work around.
output:
pdf_document:
keep_tex: yes
latex_engine: xelatex
Then open .tex file in your TEX editor and build pdf as usual.
I faced a similar issue. In my case, the error occurred because of putting a percentage inside the $ sign.
Like this,
$95%$, I removed the % sign, and everything worked fine.

.Rprofile: How to set option "browser" correctly (to Chrome) so that help.start() works?

I work on Mac OS X 10.7.3 with R version 2.14.0 (2011-10-31). My ~/.Rprofile is
options(repos=c(CRAN="http://cran.ch.r-project.org",
BioC="http://www.bioconductor.org",
Omegahat="http://www.omegahat.org/R"),
pdfviewer=path.expand("~/R/misc/shell_scripts/skim"),
browser="mybrowser")
where mybrowser is a file in /bin/ which contains open -a "/Applications/Google Chrome.app". When I open R and type help.start(), all I obtain is that Chrome becomes active, but no real output from help.start(). How can I properly set up browser in options so that help.start() works as expected?
I originally just had browser="Chrome", but R couldn't find the browser. I tried several kinds of things to solve this (e.g., browser="/Applications/Google Chrome.app" [and various variants to escape the blank]), but none worked. I guess that's because sh /Applications/Google\ Chrome.app just does not work. On the Mac, applications are opened via open -a ..., that's why I created mybrowser. That finally opened the browser, but I couldn't figure out how to get help.start to work properly.
Create a Renviron file in your home (i.e ~/.Renviron) and add this line.
R_BROWSER=google-chrome
I'm not sure about "chrome" part, i use conkeror and my setup is :
R_BROWSER=conkeror
But this should do the tricks
In the meantime, Hans-Joerg Bibiko helped out: the solution is to set browser to browser="/usr/bin/open -a 'Google Chrome'"
If you look in utils:::print.help_files_with_topic (the function that actually issues the call to browseURL()), there is this really annoying line:
if (.Platform$GUI == "AQUA" && type == "html")
browser <- get("aqua.browser", envir = as.environment("tools:RGUI"))
And since .Platform$GUI == "AQUA" on OSX, this means that you have to do some trickery to browse help files in your favorite browser. Hence, in my .Rprofile (located here path.expand('~/.Rprofile'), of course), I included these lines.
options(help_type='html')
options(browser="/usr/bin/open -a '/applications/Google Chrome.app'")
p <- .Platform
p$GUI = 'unknown'
unlockBinding('.Platform', as.environment('package:base'))
assign('.Platform', p , envir=as.environment('package:base'))
lockBinding('.Platform', as.environment('package:base'))
rm(p)
So far it doesn't seem to have any effect other than enabling use of an alternate browser, but you may want to read the section labeled "Aqua" in ?.Profile if you're worried about messing around with base.

Resources