snipt

Ctrl+h for KB shortcuts

Python 3

convert to uppercase in medit

1
2
3
4
5
6
buf = window.get_active_doc().get_buffer()
start, end = buf.get_selection_bounds()
if start:
    selection = buf.get_text(start, end)
    buf.delete_selection(True, True)
    buf.insert_at_cursor(selection.upper())
https://snipt.net/embed/df0da5cb7f35c38c95cb40d5a4927c7f/
/raw/df0da5cb7f35c38c95cb40d5a4927c7f/
df0da5cb7f35c38c95cb40d5a4927c7f
python3
Python 3
7
2019-07-15T17:54:30
True
False
False
/api/public/snipt/3237/
convert-to-uppercase-in-medit
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">buf</span> <span class="o">=</span> <span class="n">window</span><span class="o">.</span><span class="n">get_active_doc</span><span class="p">()</span><span class="o">.</span><span class="n">get_buffer</span><span class="p">()</span> </span><span id="L-2"><a name="L-2"></a><span class="n">start</span><span class="p">,</span> <span class="n">end</span> <span class="o">=</span> <span class="n">buf</span><span class="o">.</span><span class="n">get_selection_bounds</span><span class="p">()</span> </span><span id="L-3"><a name="L-3"></a><span class="k">if</span> <span class="n">start</span><span class="p">:</span> </span><span id="L-4"><a name="L-4"></a> <span class="n">selection</span> <span class="o">=</span> <span class="n">buf</span><span class="o">.</span><span class="n">get_text</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span> </span><span id="L-5"><a name="L-5"></a> <span class="n">buf</span><span class="o">.</span><span class="n">delete_selection</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span> </span><span id="L-6"><a name="L-6"></a> <span class="n">buf</span><span class="o">.</span><span class="n">insert_at_cursor</span><span class="p">(</span><span class="n">selection</span><span class="o">.</span><span class="n">upper</span><span class="p">())</span> </span></pre></div> </td></tr></table>
medit, script

Python 3

delete line in medit

1
2
3
4
5
6
buf = window.get_active_doc().get_buffer()
start = buf.get_iter_at_mark(buf.get_insert())
start.set_line_offset(0)
end = start.copy()
end.forward_line()
buf.delete(start, end)
https://snipt.net/embed/d4dd982dc192468f39a82f7ab2f8c501/
/raw/d4dd982dc192468f39a82f7ab2f8c501/
d4dd982dc192468f39a82f7ab2f8c501
python3
Python 3
6
2019-07-16T04:34:12
True
False
False
/api/public/snipt/3236/
delete-line-in-medit
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">buf</span> <span class="o">=</span> <span class="n">window</span><span class="o">.</span><span class="n">get_active_doc</span><span class="p">()</span><span class="o">.</span><span class="n">get_buffer</span><span class="p">()</span> </span><span id="L-2"><a name="L-2"></a><span class="n">start</span> <span class="o">=</span> <span class="n">buf</span><span class="o">.</span><span class="n">get_iter_at_mark</span><span class="p">(</span><span class="n">buf</span><span class="o">.</span><span class="n">get_insert</span><span class="p">())</span> </span><span id="L-3"><a name="L-3"></a><span class="n">start</span><span class="o">.</span><span class="n">set_line_offset</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> </span><span id="L-4"><a name="L-4"></a><span class="n">end</span> <span class="o">=</span> <span class="n">start</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> </span><span id="L-5"><a name="L-5"></a><span class="n">end</span><span class="o">.</span><span class="n">forward_line</span><span class="p">()</span> </span><span id="L-6"><a name="L-6"></a><span class="n">buf</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span> </span></pre></div> </td></tr></table>
medit, script