Ruby on rails indentation - indentation

It's possibly a stupid question, but I need some help as I can't find answer.
I indent some code in ROR, then later I deleted the upper layer and wanted to move that back, but i can't find the shortcut as it's quite a lot of lines of code...
example:
originally
if abc
if def
some code
some code
end
end
but now
if def
some code
some code
end

Select the text to outdent and press Shift-Tab
Info from keybindings page of the documentation: https://docs.c9.io/docs/keybindings

Related

Regex: How to extract dialogue tags from fiction, with speaker information

Totally stumped on this. I need help extracting dialogue from a story so I can hand it off for narration.
Basically, this is a problem where I have a big chunk of text (a novel), and I want to extract all the dialogue from the text in a format I can pipe into a spreadsheet.
But, I also want, if it exists, the speaker information as well. So, given a string like:
'"I'm really hungry," she said.'
I would like the values returned as:
[ "I'm really hungry", "she said" ]
If there is no dialogue, as in this example:
"I'm not hungry."
the result would just be:
["I'm really hungry."]
Is this madness? Is it even possible? I have fooled around with this regex (am not a regex guru, knowing only enough to be dangerous):
"([^"]*)"
Which seems to get the dialogue tags, but doesn't get the speaker info. Any advice in how to get the speaker info as well would be greatly appreciated. I've been wrestling with this for awhile now.
Maybe a better approach would be to get the dialogue in one field, and the entire paragraph it is found in as the second field. That could also work, but I have no idea where to start with this.
Basically I want to put these all into a spreadsheet so I can hand them off to a narrator with enough context that they know whose dialogue is who's in the story.
Any help is greatly appreciated!
It definitely is possible
Look at this regex: ^.*?'?(?P<line>\".*\")(?P<actor>[^'\n]*)'?.*?$
demo here: https://regex101.com/r/UCRZwY/5
It basically marks the outer quotes as optional, but if it does find them, stores whatever provided as '$actor' (and the line as '$line') these are of course just names i've given them, feel free to change
Note updated to include such text as part of regular sentence, see example in demo

unsure of the error in syntax of my code "expected an indented block"

Im confused as to where the errors in my syntax are occuring. I'm new to coding and am trying to learn but im lost here. the error is occuring after the
def fun2(n): during the if 0<=n: statement. if you would be kind to point out any other errors in my code it would be appreicated. for reference I am using python 2.7.9.
EDIT: I had forgotten about my established main function. that was the source of my syntax error due to my inner functions not being tabbed. Thank you to those who answered.
def main():
def fun(n):
func= (n**3)-1
def fun2(n):
for i in range(n):
if 0<=n:
func2 += i*fun(i)
if 0 > n:
func2 = 0
def fun3(m,n):
c3=[]
if m<=n:
C3.append[func2(n)]
if m>n:
c3=[]
Python is based on tabs and spaces, and you've got a line of code that is more intended than python would like it to be. Its not possible to see from your code above, but an IDE like pyCharm or a text editor like sublime text could help you out here.
Another thing to check is that you are consistently using tabs or consistently using spaces. Python doesn't like to mix the two, and even if you press only the tab key, sometimes your computer still puts in 4 or 5 spaces instead.
This is especially a problem if you copy and pasted some of the code from somewhere--who knows whether that pasted code used spaces or tabs?

Pygments syntax highlighter in python tkinter text widget

I have been trying to incorporate syntax highlighting with the tkinter text widget. However, using the code found on this post, I cannot get it to work. There are no errors, but the text is not highlighted and a line is skipped after each character. If there is a better way to incorporate syntax highlighting with the tkinter text widget, I would be happy to hear it. Here is the smallest code I could find that replicates the issue:
import Tkinter
import ScrolledText
from pygments import lex
from pygments.lexers import PythonLexer
root = Tkinter.Tk(className=" How do I put an end to this behavior?")
textPad = ScrolledText.ScrolledText(root, width=100, height=80)
textPad.tag_configure("Token.Comment", foreground="#b21111")
code = textPad.get("1.0", "end-1c")
# Parse the code and insert into the widget
def syn(event=None):
for token, content in lex(code, PythonLexer()):
textPad.insert("end", content, str(token))
textPad.pack()
root.bind("<Key>", syn)
root.mainloop()
So far, I have not found a solution to this problem (otherwise I would not be posting here). Any help regarding syntax highlighting a tkinter text widget would be appreciated.
Note: This is on python 2.7 with Windows 7.
The code in the question you linked to was designed more for highlighting already existing text, whereas it looks like you're trying to highlight it as you type.
I can give some suggestions to get you started, though I've never done this and don't know what the most efficient solution is. The solution in this answer is only a starting point, there's no guarantee it is actually suited to your problem.
The short synopis is this: don't set up a binding that inserts anything. Instead, just highlight what was inserted by the default bindings.
To do this, the first step is to bind on <KeyRelease> rather than <Key>. The difference is that <KeyRelease> will happen after a character has been inserted whereas <Key> happens before a character is inserted.
Second, you need to get tokens from the lexer, and apply tags to the text for each token. To do that you need to keep track where in the document the lexer is, and then use the length of the token to determine the end of the token.
In the following solution I create a mark ("range_start") to designate the current location in the file where the pygments lexer is, and then compute the mark "range_end" based on the start, and the length of the token returned by pygments. I don't know how robust this is in the face of multi-byte characters. For now, lets assume single byte characters.
def syn(event=None):
textPad.mark_set("range_start", "1.0")
data = textPad.get("1.0", "end-1c")
for token, content in lex(data, PythonLexer()):
textPad.mark_set("range_end", "range_start + %dc" % len(content))
textPad.tag_add(str(token), "range_start", "range_end")
textPad.mark_set("range_start", "range_end")
This is crazy inefficient since it re-applies the highlighting to the whole document on every keypress. There are ways to minimize that, such as only highlighting after each word, or when the GUI goes idle, or some other sort of trigger.
To highlight certain words you can do this :
textarea.tag_remove("tagname","1.0",tkinter.END)
first = "1.0"
while(True):
first = textarea.search("word_you_are_looking_for", first, nocase=False, stopindex=tkinter.END)
if not first:
break
last = first+"+"+str(len("word_you_are_looking_for"))+"c"
textarea.tag_add("tagname", first, last)
first = last
textarea.tag_config("tagname", foreground="#00FF00")

Turn off auto indent in sublime text 2, but

Right now in sublime text 2 when I start an if statement in Coldfusion and hit enter it will automatically indent the next line like this:
<cfif this eq that>
|
When I turn auto indent off it will leave the cursor back at the far left, which would be great, but a lot of times my code is already indented:
<cfif this eq that>
|
What I want is it to leave it where it is currently indented to, no more, no less. Like this:
<cfif this eq that>
|
Any suggestions? Thanks!
There may be other ways to make this work for you.
But, you can edit the regex string in ColdFusion.tmPreferences file under
<key>increaseIndentPattern</key>
Just add cfif and cfelse to the list
|link|meta|param|cfif|cfelse
When there is an update to the ColdFusion package though, you may have to edit again.
Edit: Make sure to update the package to the latest version. The single line tags like cfargument should not indent as expected in the updated version.
Although what you would like does not seem to be possible at the moment, see ST2 forum (maybe you posted that?)
A slightly absurd workaround that may work for you, (seems to work for me). Go to View>Syntax>Java now the auto indention should do as you please - you may lose bracket tag matching (+other things?), syntax checking may be a bit nuts (you can always flip back if necessary, try other syntax stuff), and the colour scheme will change a little, but it seems to work.
Take a look at the settings in Sublime, there is one called 'smart_indent'.
The description for this setting is:
Makes auto indent a little smarter, e.g., by indenting the next line
after an if statement in C. Requires auto_indent to be enabled.
Found some more info in the Sublime Documentation.

Making Dreamweaver more like Notepad++

I'm moving to Dreamweaver from Notepad++, and while Dw does have many better features than Notepad++, there are a few that I'm really missing.
Is there a way to make the "Home" key on the keyboard take you to the front of where the code starts, instead of the very front of the line? In Notepad++ this is how it works by default, and I don't know why anyone would want to go to the very front of the line instead of the front of the code. I use tabbing to keep it more organized, so this feature is really important to me.
How do I duplicate a line in Dw? In Notepad++ I can select the line and press ctrl + d and it automatically duplicated the code. This is awesome for something like a gallery or a table where I don't want to have to type out every line because it's so similar.
Less important, as I don't use this that often, but can you vertically select in Dw? In Notepad++ you can hold down alt and select lines vertically. Ex:
http://dl.dropbox.com/u/12147973/vert-select.jpg
Thanks in advance.
For #2, check out the Code Extras extension for Dreamweaver
No Longer works in DW5.5; Try here - http://yoropan.com/en/archives/544
I was also wanting some of this features... I discovered that, at least in CS6, #2 is already in Dreamweaver, but the shortcut is Ctrl+Alt+Down ou Up, depending on the direction that you wanna duplicate the code.
Note that I had to disable the shortcut that turns your screen view for that to work. (It's an intel default, press Ctrl+Alt+f12 to open the options)
And tãa dãaa... IT WORKS! :D
I want to say one thing different. My Dreamweaver theme (Users who use Dreamweaver after use Notepad++). Download Dreamweaver.xml
"Dreamweaver.xml" file is in here for windows: C:\Program Files\Notepad++\themes\Dreamweaver.xml
The answer to #1 = Ctrl+Home in anything in windows will take you to the absolute start of the documents, same as Ctrl+End, Home and End to start and finish of lines, Ctrl+Left or Right arrow to jump entire words...
I too am on the quest for duplicating lines in DW. #3 your image no longer shows.
If I want to duplicated a line I click on the line number, then CTRL+C to copy and CTRL+V to paste. Is that what you're looking for or am I being simple?