How to insert "n" org-mode checkboxes interactively (with yasnippets or else)? - org-mode

To organize reading tasks, I use org-mode checkboxes in the following way:
* TODO author, book_title [3/12]
- [X] chapter_01
- [X] chapter_02
- [X] chapter_03
...
- [ ] chapter_12
Since it is tedious to write this up for every book, I was thinking of using yasnippets to come up with some interactive snippet that would take as argument the "n" number of chapters and produce something of this sort:
- [ ] ${1:chapter_title_01}
- [ ] ${2:chapter_title_02}
...
- [ ] ${n:chapter_title_0n}
that would allow me to input the chapter titles one by one.
My elisp knowledge is limited, so the question is: Has anybody succeeded in implementing something similar with yasnippets or else? Thanks!

You probably don't need a snippet or a function. Try the following workflow:
Enter the headline with the title of the book.
Enter a '-' and then press M-S-RET: the dash moved down to the next line and you get a checkboxed list item.
Enter the title of the first chapter ending with M-S-RET and continue on like this until you've run ouf of chapters.
Finally delete the dash at the end.
That'd be enough for me, but YMMV: try it and see!

Related

how to add different number at end of multi line edit?

Having trouble finding a way to do this, maybe it is not even possible?
In my case, for testing flow of if-statements/user-interaction, am temporarily adding 40 lines of console.log('trigger-fired-1'); throughout our code.
However, to tell them apart would like each to end with a different number, so in this case, numbers one to forty like so:
In the screen recorded gif, to replicate what I am going for, all I did was copy/paste the numbers one to nine. What I really would like is a shortcut key to generate those numbers at the end for me to eliminate that step of typing out each unique number.
Am primarily coding in Visual Studio Code or Sublime Text, and in some cases shortcuts are similar, or at least have same support but for different shortcut keys.
There are a few extensions that allow you to do this:
Text Pastry
Increment Selection
NumberMonger
For Sublime Text, the solution to this problem is the internal Arithmetic command. Something similar may or may not be available in VS Code (possibly with an extension of some sort) but I'm not familiar enough with it to say for sure.
This command allows you to provide an expression of some sort to apply to all of the cursor locations and/or selected text.
By way of demonstration, here's the example you outlined above:
The expression you provide is evaluated once for every selection/caret in the buffer at the time, and the result of the expression is inserted into the buffer (or in the case of selected text, it replaces the selection). Note also that when you invoke this command from the input panel (as in the screen recording) the panel shows you a preview of what the expression output is going to be.
The special variable i references the selection number; selections are numbered starting at 0, so the expression i + 1 has the effect of inserting the selection numbers starting at 1 instead of 0.
The special variable x refers to the text in a particular selection instead. That allows you to select some text and then transform it based on your expression. An example would be to use x * 2 immediately after the above example (make sure all of the selections are still present and wrapping the numbers) to double everything.
You can use both variables at once if you like, as well as anything in the Python math library, for example math.sqrt(i) if you want some really esoteric logs.
The example above shows the command being selected from the command palette interactively, where the expression automatically defaults to the one that you want for your example (i + 1).
If you want to have this as a key binding, you can bind a key to the arithmetic command and provide the expression directly. For example:
{
"keys": ["super+a"],
"command": "arithmetic",
"args": {
"expr": "i+1"
},
},
Try this one ...
its not like sublime
but works g
https://github.com/kuone314/VSCodeExtensionInsertSequence

RubyMine reformatting

This is in the RubyMine IDE.
It seems really simple but I can't find a way to do it. I want to take a line
[:a, :b, :c]
and as part of the reformatting rearrange each value to one line like so:
[
:a,
:b,
:c
]
And assign a nice little keyboard shortcut.
Any idea how I do this? RubyMine documentation isn't great.
Not familiar with a way to use the IDE reformatter for this need.
But, you can achieve the rearrangement using the find an replace tool (CTRL + R).
Mark the regex checkbox.
In the find box look for space - ().
In the replace box, insert newline - \n\t.
Then hit Replace all - it should do most of the job.

Emacs - org-mode insert checkbox

I am starting to use org-mode, to organise... well everything.
I am following the manual.
Is there a binding in org-mode to insert items and checkboxes ?
Ie. something like this :
* TODO Organize party [2/4]
- [-] call people [1/3]
- [ ] Peter
- [X] Sarah
- [ ] Sam
- [X] order food
- [ ] think about what music to play
- [X] talk to the neighbors [CURSOR HERE]
And now if I do M-x insert-checkbox-item (or similar, I haven't found the command) :
* TODO Organize party [2/4]
- [-] call people [1/3]
- [ ] Peter
- [X] Sarah
- [ ] Sam
- [X] order food
- [ ] think about what music to play
- [X] talk to the neighbors
- [ ] [CURSOR HERE]
If possible, it would respect the indentation too. This would mean keeping the new item at the level of indentation of the item where the cursor was when invoking the command. Which means that it may have to skip a few lines of lower-level items.
Assuming point is already in a list like in your example, use org-insert-todo-heading, bound to M-S-return in Org by default. When point is in a checklist item C-c C-c will toggle its state.
This same binding will do other things depending on where point is, e.g. if you are at the end of a heading it will add another heading at the same level with a TODO keyword.
Just C-u C-c C-c would do wherever your cursor on that line
Ref: https://orgmode.org/manual/Checkboxes.html
For continuing checkbox lists (and ordinary lists) in org-mode I use org-autolist.
This should do exactly what you want.
Also, for creating a new checkbox item I defined an emacs abbrev like so:
("rr" "- [ ]")
This means that I can type "rr " and emacs inserts "- [ ] " which is great.

Eclipse - custom quick fix - Add some text before and after selection

I could use a dummy guide or directions how to add a custom quick fix or if it is even possible.
Let's say I select a text inside code - "foo foo". Now I want to add something before that text and something after. The content before and after remains the same across many files and it has to be done manually.
Is there a way I could write my own quick fix in eclipse, which would add this text automatically.
Ctrl + 1 -> "Add ... before and ... after" -> And get the desired output?
This seems somewhat useful if not the correct thing, but I can't exactly read out how to accomplish this: FAQ How do I implement Quick Fixes for my own language?
Any easier explanations and guides are appreciated. Or what other ways would I have to accomplish this desired behavior without typing/copying repetitive things
Edit: Found this little macro thing which is one way to solve my problem. start with cut, write, paste and end macro. But I'm not sure if this is the best way. Practically Macro
I suggest this solution that allow you to get the result using Eclipse search.
CTRL+H to do a search and choose Files Search
Fill Containing text with "foo foo". Tweak other parameters to get the files you want
Check Regular expression
Click on Replace
Fill With: <prefix>$0<suffix>. For example if you want to substitute "foo foo" with "this is a foo foo example" write this is $0 example
Check Regular expression (if unchecked).
Done. I think that this solution is quite flexible (as long as you are familiar with regexp to get desidered strings) and easy to apply.

How to prevent "."(dot) from cancelling autocomplete in Sublime Text 2?

I have defined some keywords for a proprietary language I use at work:
{ "match": "\\b(util.tickettimelimit|util.user_ip|util.server_name|util.today)\\b",
"name": "keyword.source.GTX2",
"comment": "Tags"
}
I also have a completion file:
{
"scope": "source.GTX2",
"completions":
[
"util.server_name",
"util.tickettimelimit",
"util.today",
"util.user_ip"
]
}
When I start typing "util" I see the correct autocomplete options:
But as soon as I enter the "."(dot) autocomplete options go away:
Is there a way to change this behavior? I just want the keywords to be trated as a whole thing and ignore the dots.
Thanks!
I've looked everywhere I can, and it seems the auto-complete code is embedded within the executable itself (at least on Windows, I haven't checked my Mac yet), and not in one of the numerous external .py files scattered around, so I can't even see the parameters for how auto-completion is performed. I looked through the default Packages/Default/Preferences.sublime-settings file and while there are several options relating to auto-complete, there are none relating to what we're looking for. While looking through the Default (Windows).sublime-keymap file in the same directory, I tried adding the following:
{ "keys": ["."], "command": "hide_auto_complete", "context":
[
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
]
},
but alas it didn't work. There are a number of auto_complete commands there, and while this looked the most promising I haven't tried the rest.
I haven't exhaustively looked through the source and config files for the nifty SublimeCodeIntel plugin (also available through Package Control), so it's possible you might be able to find an option there. You'd probably have to completely disable the built-in auto-complete functionality first, so it doesn't override SCI.
So, I guess for now there's not much you can do. You can always leave a feature request and see if it makes it into Sublime Text 3, or search/open a thread on the Sublime Text Forum and see if anyone else has any suggestions. Good luck!
What I think #Ashish is alluding to is the word_separators setting. You will want to create a syntax specific preference (Preferences -> Settings - More -> Syntax Specific - User). Create a word_separators entry with the dot removed (Copy from the default preferences as the base). This will give you the behavior you want but there are some things to note. The dot, obviously, will not be treated as a word separator, which will change some behavior.
I'll use java as an example. If I had a variable foo, with some method bar, I could enter foo.b and bar would be shown as a completion. Without the dot as a separator, you will not see this.
Another example, perhaps easier to understand is when selecting words. If you use ctrl/cmd + d to select the word, it selects words, bound by word separators. So if I had foo.ba|r, where the | represents the cursor position and used ctrl/cmd+d it would select bar. With the dot removed as a word separator, foo.bar would be selected.
Let me know if I can clarify anything.
It's a little late but I hope this can help, create a new plugin and add this code:
import re
myObjects = {"util": ["server", "tickettimelimit", "today", "user_ip"]}
class CustomAutocomplete(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
if not view.match_selector(0, "source.GTX2"):
return
if prefix == "":
# get the last word in the current line
currentposition = view.sel()[0].begin()
currentline = view.full_line(currentposition)
text = view.substr(currentline)
words = re.findall("\w+", text)
lastword = words[-1]
if lastword in myObjects.keys():
# return a list of tuples, it represents snippets
# the first element is the trigger and the second one
# is the content
return [(x, x) for x in myObjects[lastword]]
return []
And add the next key in the user settings:
"auto_complete_triggers":
[
{
"characters": ".",
"selector": "source.GTX2"
}
]
Don't press . (dot) else you will need to type at least one character after dot so list can appear again. Using Brackets or Dot tells Sublime Text 2 that user has completed typing.
example: if I type for then sublime will show dropdown list but if I type for( list will disappear.
Click on Preferences > Settings - User, then copy and paste the following
// Characters that are considered to separate words – does not include periods.
// Place comma at the end of the line if there are multiple keybindings.
"word_separators": "/\\()\"‘-:,;~!##$%^&*|+=[]{}`~?"
From this webpage:
http://tomschenkjr.net/using-sublime-text-2-for-r/