Aptana 3 Code Folding - aptana

Ive started using Aptana 3 today and really like it,
However I'm struggling to find out if I can code fold to specific levels.
For example I can push Ctrl+Shift+Divide and will collapse EVERYTHING imaginable.
Including the class.
lets just say my doc is as follows:
class Kill_model extends Game_Model{
function shoot(){
//code
//code
//code
//code
//code
}
function respawn(){
//code
//code
//code
//code
//code
}
function spectate(){
//code
//code
//code
//code
//code
}
}
The default will collapse to
class Kill_model extends Game_Model{}
I've been using PHPEdit in the past, and like to "Fold to Level 2"
This gives me the appearance of
class Kill_model extends Game_Model{
function shoot(){}
function respawn(){}
function spectate(){}
}
I was wondering if its possible to just fold down to level 2, by level 2 I assume it means 2 levels deep. Level 1 = Class, level 2 = functions within.
Many thanks.

Ok, so level folding is available in Aptana, it just isn't built into PHP editing, only Source editing. To add it to PHP, you can go to Commands > Source > Edit this Bundle, and the Commands > PHP > Edit this Bundle and copy Source/commands/folding.rb to PHP/commands/folding.rb (this will be a new file). If you do not have Option and Command keys (Mac, I believe), you will want to change the keybindings in this file to something else, like Control and Alt. You will find the keybinding in the folding.rb file looking something like this:
with_defaults :input => :none, :output => :discard, :key_binding => "OPTION+COMMAND+0" do
and a second time like this:
cmd.key_binding = "CONTROL+ALT+" + level.to_s
Just change the OPTION to CONTROL and the COMMAND to ALT, and you will have a new Ctrl+Alt+ shortcut once you restart Aptana.

See my second answer for more direct info... I thought I'd leave this one in case it helps someone with a similar but not quite the same problem...
I can't speak for the keyboard shortcut because I don't know where numpad_divide is on my laptop (no numpad) - but if you look under Window > Preferences > Aptana Studio > Editors > PHP, you can choose to initially fold "these elements" - if you check "Functions" I think you may get the folding you are looking for. However, I do not think this preference will affect the behavior of Ctrl+Shift+Divide aka Collapse All.
There is also a command to collapse the current block (Ctrl+Numpad_minus) but I think this would be less useful to you.
You may also find the Quick Outline helpful, if you are looking for a short overview of the available classes and functions in your file. This can be accessed with Ctrl+O (or right click > Quick Outline).
Edit: Playing around with Aptana today I found, under Commands > Source > Folding > Toggle Foldings at Level > Level <x>. There appears to be a shortcut associated with each level, Alt+1, Alt+2, etc. but it doesn't work for me. I also don't see an option to configure a shortcut for these commands, but you can theoretically make your own.

Related

Is there a way to jump to last edited cell in Jupyter?

Often in Jupyter I'd move to different parts of the notebook to look at something, and when I am done I want to jump back to where I was working on previously. Right now I'd have to navigate to the closest Markdown section (through the Jupyter Notebook Extensions) and move up or down to get to where I was. Is there a way to jump directly to the last cell that I have made an edit (preferably through keyboard shortcut)? Thanks!
Ideally this would be a built-in shortcut of course, but in the meantime:
Option 1: Custom JavaScript
If you get a browser extension like Custom JavaScript for Websites 2 (open-source), then you can use this code to record a stack of scroll position histories and jump backwards with Ctrl+Shift+X:
// Visit JupyterLab in browser and click the Custom JS browser extension icon and then paste this:
if(location.href.startsWith("http://localhost:8888/lab")) {
let scrollLocationsHistories = new Map();
let scrollBinHeight = 100;
window.addEventListener("keydown", (e) => {
let notebookEl = document.querySelector(".jp-mod-searchable .jp-NotebookPanel-notebook");
if(!scrollLocationsHistories.has(notebookEl)) scrollLocationsHistories.set(notebookEl, [])
let scrollLocationsHistory = scrollLocationsHistories.get(notebookEl);
if(e.ctrlKey && e.shiftKey && e.key === "X") {
if(scrollLocationsHistory.length > 0) {
e.preventDefault();
let origScrollPos = notebookEl.scrollTop;
notebookEl.scrollTo(0, scrollLocationsHistory.pop()*scrollBinHeight);
let newScrollPos = notebookEl.scrollTop;
if(Math.abs(origScrollPos-newScrollPos) < scrollBinHeight && scrollLocationsHistory.length > 0) {
notebookEl.scrollTo(0, scrollLocationsHistory.pop()*scrollBinHeight); // jump back again because last edit position was close to current position
}
console.log("Scroll History (newest locations at end):", scrollLocationsHistory.map(v => v*scrollBinHeight))
}
} else if(!e.ctrlKey && !e.shiftKey && document.activeElement.tagName.toLowerCase() === "textarea") {
let scrollBin = Math.round(notebookEl.scrollTop/scrollBinHeight);
if(scrollLocationsHistory[scrollLocationsHistory.length-1] !== scrollBin) {
scrollLocationsHistory.push(scrollBin);
if(scrollLocationsHistory.length > 500) scrollLocationsHistory = scrollLocationsHistory.slice(-250);
}
}
});
}
It's just an initial prototype, but it seems to work quite well so far. You may want to adjust it a bit - e.g. scrollBinHeight causes nearby edits that are within scrollBinHeight pixels of one another to not create a second history entry. You'll need to edit http://localhost:8888/lab to match the URL that you want to enable it on. If you're reading this long after I've written it, then you may also need to change document.querySelector(".jp-mod-searchable .jp-NotebookPanel-notebook") (i.e. the main scrolling element of the active notebook) in case they've updated the HTML class names, or HTML structure.
Option 2: Fold Often
Another possible option (which may be impractical depending on your use case) is to get used to folding cells that you're not currently working on. That makes it much easy to quickly scroll between cells that you're working on.
Option 3: Search Hack
If you're working on a particular cell but often have to jump to another one, you can add a comment like #vv (or any random easy-to-type string) to both of those cells and then whenever you need to jump between them, just press Ctrl+F and then Enter. The first time you do this you'll obviously need to type vv in the search box, but after that it'll be remembered (unless you use the search for another string). The disadvantage of this approach is that you need to "prune" the #vvs from cells that you're no longer working on.
echap to go to command mode, then Ctrl + z will undo your last change, which will bring the focus on the last edited cell. ctrl + y will redo the last modification.
(Only tested on python3 kernel)
EDIT Actually if you press ctrl + z just once, you only get the focus part, without modifying your cell. Then press enter to go to edit mode, which scrolls the page to the active cell.

Atom - Force Tab Width 2

I just switched from Sublime Text to Atom in order to turn completely open source.
I have trouble with something very very simple: I want Atom to use always (!) and under any circumstances tab width 2 and replace tab with spaces. This setting is so simple in gedit or Sublime Text, but no matter what I am trying: When I start a new file, tab size is 2 (good!). When I use an existing file, tab size is sometimes 4. I find that a bit annoying.
My current setting in Editor are seen in the screenshot:
There is more than one tab setting
Each package (such as python-language) has its own tab setting(s). Whether the language uses the global default or its own default is up to whoever created the package, but you can generally override it.
In your screenshot, you have set the "Tab Type" to "soft". That will take care of using spaces rather than tabs. You have left the default tab width of 2. That is your global setting.
Now, if you look under "Packages" and search for "python" you will find a package named "language-python". Click on its settings button and you will find a number of syntax-specific settings.
Python Grammar
Python Console Grammar
Python Traceback Grammar
Regular Expressions (Python) Grammar
Each of those grammars has its own Tab Length setting. You can set them explicitly to 2 here to override the package's default. (You probably mostly care about the first one, Python Grammar.)
Python is different
In the case of Python, the package is explicitly configured to default to 4 spaces, probably because Python is very opinionated about whitespace, and PEP 8 recommends 4-space indents. You can see the default package setting here in the package's source:
https://github.com/atom/language-python/blob/master/settings/language-python.cson
'autoIndentOnPaste': false
'softTabs': true
'tabLength': 4
This overrides the global default. That's why Python Grammar does not honor the global tab width, the way that most packages do.
Sometimes there are package overrides
Additionally, certain packages will override your settings for syntax reasons. For example, language-make will override and use real tabs instead of spaces, because that is required by make.
In the case of Python, there is an override to use spaces. The language-python settings page offers a spot for you to change the indentation level, but it does not offer a way to switch to using tab characters. (That's probably justifiable, as tab characters and mixed indentation in Python are a very common cause of difficult-to-debug syntax errors.)
You might need to reload
Lastly, sometimes settings don't take effect completely until you reload the Atom window. You can use the Window: Reload command to do so. Or using the keyboard:
Mac: CtrlOptCmdL
Windows/Linux: CtrlAltR
This is what worked for me.
Disable all non-default packages
Open ~/.atom/config.cson, and append this (same level than the "*" element)
:
".python.source":
editor:
autoIndent: true
tabLength: 2
Re-enable all packages.
I got this help from someone else. Not my own discovery. However, for confidentiality, I cannot cite the source.
Based on soham's answer, I found that setting all tabLength: fields in ~/.atom/config.cson (assuming osx) to your desired length solved the problem.

How to change command-palette scroll key bindings in atom

I'm a new Atom user and I want to override the Atom command palette (shift-ctrl-p) scrolling key bindings to something more vi friendly like
ctrl-n and ctrl-p instead of the annoying arrow keys (which force me to take my hands off the home row).
Just to be clear, I don't want to change the key binding that brings up the command palette, but the key bindings you use to scroll through the list once it's up:
I can only find a binding to override the command palette toggle:
As you can see in the following config file, I was able to override the autocomplete scrolling, and I hope to do the same with the command palette. I've tried 'command-palette:up' ,'command-palette:down' and 'command-palette:move-up' etc. to no avail.
Here's is my keymap.cson.
# Atom Flight Manual:
# https://atom.io/docs/latest/using-atom-basic-customization#cson
#vt add
'body atom-text-editor.autocomplete-active':
'ctrl-p': 'autocomplete-plus:move-up'
'ctrl-n': 'autocomplete-plus:move-down'
'alt-p': 'autocomplete-plus:page-up'
'alt-n': 'autocomplete-plus:page-down'
'home': 'autocomplete-plus:move-to-top'
'end': 'autocomplete-plus:move-to-bottom'
# vim-plus ex mode 2016-04-18
'atom-text-editor.vim-mode-plus.normal-mode':
':': 'vim-mode-plus-ex-mode:open'
'!': 'vim-mode-plus-ex-mode:toggle-setting'
# add cmd palette key bindings --> These do not work.
'body .native-key-bindings':
'ctrl-p': 'command-palette:up'
'ctrl-n': 'command-palette:down'
#vt end
I've been really impressed with the key binding support in Atom thus far. I'd be really surprised if it couldn't handle this but, alas, I think this might be the case.
Does anyone know of a way to do this?
Atom 1.7.2, linux
I was able to get single line scroll to work, but not page scroll to work with the following in my keymap.cson:
'atom-workspace':
# these work
'ctrl-p' : 'core:move-up'
'ctrl-n' : 'core:move-down'
# these don't work
'alt-p' : 'core:page-up'
'alt-n' : 'core:page-down'
It would be nice to have page scroll as well, but I should be able to narrow down the list down by typing in text, so I don't foresee needing page-up, page-down all that often.
Now I'm happy.
To target keybindings for just the command palette, you can find an appropriate selector by looking in the command-palette repo keymaps: https://github.com/atom/command-palette/blob/v0.43.5/keymaps/command-palette.cson
This suggests the use of the .command-palette selector, which seems more appropriate then atom-workspace.
'.command-palette':
'ctrl-n': 'core:move-down'
'ctrl-p': 'core:move-up'
I was not able to find a mapping to scroll a page at a time within the command palette, though I'm sure someone else can figure it out. The keyboard page up/down keys have no effect so mapping to core:page-down etc. is not going to work.

Override default Console help text

I want to cleanly override part of the default text output by Symfony\Component\Console when either the help or list command is used. In particular, the gratuitous line wrap of the verbosity option bugs me a lot although I may ultimately want to alter the rest of the help/list text a bit as well.
I.e. this line of output:
--verbose -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug.
Would be nicer if I could change it to something like:
--verbose -v|vv|vvv Set verbosity level.
I could subclass Symfony\Component\Console\Application and override the getDefaultInputDefinition() method.
I perhaps could use a combination of getDefinition() and setDefinition() to fiddle with the InputDefinition object.
But these don't seem to be very maintainable.
Is there some other, better, way to accomplish this?
Try this. I'm not certain it will work but looks like the closest solution.
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputOption;
public function overrideVerboseInputOption(Application $application)
{
$verboseOption = $application->getDefinition()->getOption('verbose');
$customVerboseOption = new InputOption(
$verboseOption->getName(),
$verboseOption->getShortcut(),
InputOption::VALUE_NONE,
"Set verbosity level"
);
$options =& $application->getDefinition()->getOptions();
unset($options['verbose']);
$application->getDefinition()->addOption($customVerboseOption);
}

Multiple script/paperscripts in the same paperscope

I'm starting with paper.js. I like the fact that it introduces the possibility to have a script with a text/paperscript mime type, which runs in its on scope. However, scripts can become large pretty soon, so I want to be able to divide it in multiple scripts for readability. I thought I could just add more than one script tag and have them all run in the same scope, but apparently this isn't the case.
Both scripts are loaded and do run, but the second script doesn't seem to be in the paper scope.
I've set up an example here: http://barbata.nl/SO/Maps/ This example has some code, but I'll point out the important bits.
It contains two paperscripts:
Maps.js is the main script, which rasterizes the image and allows moving it around. You can ignore the code in this script, for it works fine so far.
Zoom.js is the script in which I wanted to isolate zooming functionality. It uses jq.mobi to capture the scroll wheel of the mouse, since Paper.js doesn't seem to have that event. It then translates that to a call to onMouseScroll, in a similar way Paper does it.
So far so good. The actual problem arises with the zoomIn and zoomOut functions in zoom.js.
It works if I explicity use the paper object to reference the view I want to zoom:
function zoomIn()
{
if (paper.view.zoom < 2)
{
paper.view.zoom = paper.view.zoom * 2;
}
}
But it fails when I remove paper and just reference the view:
function zoomIn()
{
if (view.zoom < 2)
{
view.zoom = view.zoom * 2;
}
}
This surprises me, as I expected the script to be a Paperscript, running in the Paperscope. It works fine if I put this code in Maps.js, so it seems that although zoom.js is loaded by Paper.js (the developer tools in the browser confirm this), it isn't run in the Paperscope.
My question is: are my findings correct? Am I doing something wrong? What is the right way to divide a Paper.js application into multiple units for readability?
Of course I can get it running, but I want to make sure I do it right.
This is indeed how it works. I've opened an issue on GitHub
I found that the "cleanest" way is to do it with this.install(window). It also makes error finding with Chrome developer tools easier since it is more adapted to reporting on the line errors in java-script than "paperscript".
in index.html (for example):
<script type="text/javascript" src='js/other_lib.js'></script>
<script type="text/paperscript" canvas="canvas">
this.install(window);
/*no code 'required' here */
</script>
<body>
<canvas id="canvas" width="1500" height="500"></canvas>
</body>
Then in the js/other_lib.js i just add code as normal:
var r = new Path.Rectangle([100,100],[200,200]);
r.fillColor = 'black';
/*more code here*/
This should generate a rectangle.
What DOES'T NOT WORK for me (as of Paper.js v0.10.2 Release Date: 9. July 2016) is the object operators. Such as adding vecrots pointc = pointa + pointb; for me this is giving a lot of NaN values.
I have had to edit a few libs to get this working, but the change is simple:
var pointc = new Point(pointa.x+pointb.x,pointa.y + pointb.y);

Resources