Showing posts with label Eclipse. Show all posts
Showing posts with label Eclipse. Show all posts

6/25/2019

Ubuntu Eclipse/Console font to use: Consolas High (font size: 10.5)

The default Consolas font is too low so that lines look crowded. The solution is to use the Consolas High font.
In One Drive | ubuntu_home | Consolas-High-Line-master..zip

https://github.com/Salauyou/Consolas-High-Line

6/03/2019

How to setup Eclipse PyDev to run yapf and buildifier on save

Worked for my Eclipse version (May or may not work with other versions)
Eclipse IDE for C/C++ Developers
Version: Photon (4.8), Oxygen (4.7)

I. Save this file to: $HOME/eclipse-workspace/pydev_scripts (this is a folder, not a file). The file name should be pyedit_pydev_formatter.py

----------Begin of Script------------------------------------------------
"""
This script makes Eclipse PyDev smart to autoformat .py and BUILD files on save.
"""

# Ensure that yapf and buildifier are executable (chmod +x).
# Change the red text to your yapf and buildifier paths.
ABS_PATH_TO_YAPF = '/usr/local/bin/yapf'
ABS_PATH_TO_BUILDIFIER = '/home/liangzou/bin/buildifier'

if False:
    from org.python.pydev.editor import PyEdit  #@UnresolvedImport
    cmd = 'command string'
    editor = PyEdit

assert cmd is not None
assert editor is not None


def run_formatter():
    ENABLED = True
    try:
        doc = editor.getDocument()
        sel= editor.getSelectionProvider().getSelection()
        startLine = doc.getLineOfOffset(sel.getOffset())
        editor.performSave(True, None)

        file_path_full = str(editor.getEditorFile())
        formatter = ''
        flags = ''
        if 'BUILD' in file_path_full:
            bin_to_use = ABS_PATH_TO_BUILDIFIER
            formatter = 'buidifier'
        elif file_path_full.endswith('WORKSPACE'):
            ENABLED = False
        else:
            bin_to_use = ABS_PATH_TO_YAPF
            formatter = 'yapf'
            # flags = '-i --style="{based_on_style: google}"'
            flags = '-i'
        if ENABLED:
            os.system('%s %s "%s"' % (bin_to_use, flags, file_path_full))
            print('%s formatted by %s' % (file_path_full, formatter))

        with open(file_path_full) as f:
            # Got the functions from:
            # https://help.eclipse.org/neon/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/jface/text/ILineTracker.html
            lines = []
            for each_line in f.readlines():
                clean_line = each_line.rstrip()
                if clean_line:
                    lines.append(clean_line)
                lines.append('\n')
            doc.set(''.join(lines))

            # Got the functions from:
            # https://help.eclipse.org/kepler/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/ui/texteditor/AbstractTextEditor.html
            editor.performSave(True, None)

        sel = TextSelection(doc, doc.getLineOffset(startLine), 0)
        editor.getSelectionProvider().setSelection(sel)
    except Exception, e:
        print(e)
        self.beep(e)


if cmd == 'onCreateActions':
    import os

    from org.python.pydev.editor.actions import PyAction
    from org.python.pydev.core.docutils import PySelection
    from java.lang import Runnable
    from org.eclipse.swt.widgets import Display
    from org.eclipse.jface.text import TextSelection

    FORMAT_ACTION_DEFINITION_ID = "org.python.pydev.editor.actions.pyFormatStd"
    FORMAT_ACTION_ID = "org.python.pydev.editor.actions.navigation.pyFormatStd"

    class PythonTidyAction(PyAction):
        def __init__(self, *args, **kws):
            PyAction.__init__(self, *args, **kws)

        def run(self):
            run_formatter()

    def bindInInterface():
        act = PythonTidyAction()

        act.setActionDefinitionId(FORMAT_ACTION_DEFINITION_ID)
        act.setId(FORMAT_ACTION_ID)
        try:
            editor.setAction(FORMAT_ACTION_ID, act)
        except Exception, e:
            print(e)

    class RunInUi(Runnable):
        """Helper class that implements a Runnable (just so that we can pass it
        to the Java side). It simply calls some callable.
        """

        def __init__(self, c):
            self.callable = c

        def run(self):
            self.callable()

    def runInUi(callable):
        """
        Args:
            callable: the callable that will be run in the UI
        """
        Display.getDefault().asyncExec(RunInUi(callable))

    runInUi(bindInInterface)


----------End of Script------------------------------------------------

II. Then open
Preferences | PyDev | Scripting PyDev | Location of additional Jpython scripts: /home/liangzou/eclipse/pydev_scripts  (NOTE: this is the parent folder of the script.) Check the "Show the output given from the scripting to some console?" for debugging purpose.

III. Preferences | Keys, search for Python Format Code and change the Binding to ctrl+s.

When you press ctrl+s to save the .py and BUILD files, they'll be automatically formatted.
If it doesn't work, you can modify the script, then reopen the python file so that the pydev_scripting file can be reloaded.

11/22/2017

Commonly used eclipse shortcut

ctrl+shift+r: search and open a file
ctrl+/: block comment
alt+/: auto complete a work that exists in the workspace (This may not work if the Desktop is not cinnamon. Use Linux cinnamon desktop for this feature)
ctrl+q: go to the last edit place
ctrl+l: go to line number
ctrl+shift+g: find the reference of a function
ctrl+d: delete a line
alt+up or alt+down: move the line up or down
ctrl+up or ctrl+down: scroll windows up or down
ctrl+shift+h: search a keyword in the workspace
ctrl+alrt+r: show git revision history

5/26/2017

Eclipse Java autoformatter line wrapping settings


Uncheck Prefer wrapping outer expressions(...)

3/24/2017

Eclipse python format settings

Window | Preference | PyDev | Editor | Code Style | Code Formatter
Check: "Use space after commas" "Use space before and after assign for keyword arguments" "Right trim lines" "Right trim multi-line string literals" "Add new line at end of file"

# How to make Eclipse python indent two spaces Window | Preference | PyDev | Editor | Tabs
Change Tab length to 2

7/15/2016

Thank YOU, Eclipse!!

Every time I did something stupid to purge my whole folder, it's Eclipse that saved my work.
I really want to say THANK YOU Eclipse! The best code editor ever!

6/15/2016

Debug Shortcuts

Eclipse:
Step Info: F5
Step Over: F6
Step Return: F7
Continue: F8

5/06/2016

Setup Eclipse

(On Windows, cygwin or MinGW gcc must be installed. When creating a new project, Cygwin GCC must be selected.)

How to add an existing GIT project to Eclipse?
Install EGit from Market Place
Open Git Perspective, in Git Repositories | click Add an existing local Git Repository ...

In Project Explorer | Import | Git (Projects From Git) | Existing local repository | select the local Git Repository that was just imported.

Choose "Import using the New Project wizard" | Makefile Project with Existing Code | Fill the name and location of code.

After importing the Git repo, need to use the Exclude Build option to exclude some folders from building.
Right click on the folder | Resource Configurations | Exclude from Build | Select or Deselect | OK

Also need to mark some folders as derived, such as bazel-* folders. Right click on the folder | Resources | Click "Derived"

Also need to remove derived folders from sources. Project Property | C/C++ General | Path and Symbols | Source Location | Edit Filter | Remove bazel-bin,bazel-deepmap,bazel-testlogs etc.

Install Plugins:
Protocol Buffer: Install from Eclipse Marketplace
sudo snap install beautysh: Install Bash editor, then Save Actions: execute command on save beautysh $filename

C++ Formatter:
Install CppStyle from market place and use clang-format.


C++ symbol/function could not be resolved:



NOTE: The project must have the 'includes' folder, which contains the C++ headers, also make sure the static folder has all the necessary header files. If something doesn't resolve, DON'T rebuilt it over and over again. Just make sure the header can be found in the project and click Project | C++ Index | Resolve Un-resolved includes. If it doesn't resolve by doing that, rebuilding the whole thing doesn't help either.

First: Disable build automatically




1. Project Property | Preprocessor Include | Providers | CDT GCC Built-in Compiler Settings | Command to get compiler specs:
Add -std=c++11 to the Command to get compiler specs.

Open Window | Preferences | C/C++ | Build | Settings | Discovery | CDT GCC Build-in Compiler Settings
Append -std=c++11 to the Command to get compiler specs
Press OK

Rebuild the index: Project | C/C++ Index | Rebuild

2. Add third party dependency:
Project Property | C/C++ General | Paths and Symbols | Source Location | Link Folder
Choose the folder that has the third party dependency.

Add protos to the Source Location:
bazel-deepmap/bazel-out/local-fastbuild/genfiles/protos/

Project | Clean then Project | C/C++ Index | Rebuild

3. Enable auto completion
Window | Preferences | C/C++->Editor->Content Assist | Auto-Activation | Advanced
Enable: Help Proposals, Parsing-based Proposals, Template Proposals

Possible issues:
================
1. Column margin (ruler) is at wrong position:
Upgrade to Photon 4.8 version fixed it.

2. Ctrl + Click not working:

To work around the problem, you can disable the Change Log hyperlink by going to Window | Preferences | General | Editors | Text Editors | Hyperlinking, then untick "Changelog Detector"

Change selection color:
General | Editors | Text Editors, change Selection background color to #FF7F00

How to Import existing projects to a new workspace:
===================================================
Import | General | Existing Projects into workspace | Locate the workspace AND CHECK 'Copy projects into workspace'

/bin/cp -rf /mnt/machome/liangzou/workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings ~/workspace/.metadata/.plugins/org.eclipse.core.runtime/

.md file editor
================
Use WikiText editor to open it.
Change settings: Colors and Fonts | WikiText | Monospace Font. Change it to Hack 9 (the same as Text Font).
General | Editors | Text Editors | WikiText | Appearance, change all places that use font-family: monospace to font-family: Hack, monospace; font-size: 9pt;

BUILD file editor
=================
TBD

Disable caret blinking
======================
For Ubuntu cinnamon, System settings | Keyboard turn off text cursor blinking
Then in Eclipse settings, search for caret, click Enable custom caret
 
Setup Javascript
==============
Eclipse 2024.09
The default javascript editor is not supported anymore. To use the previous Javascript syntax coloring:
1. Install the Web development tools
2. Open a *.js file, right click and select Switch to Theme
3. How to edit the theme? In the preference, search for theme under TextMate. Add OneDrive/liang-textmate-Light.css as one of the themes. (Find all the css files used by Eclipse: https://github.com/eclipse-tm4e/tm4e/releases/tag/0.14.0, download the source code and find in the folder of org.eclipse.tm4e.ui/themes/)

Setup Python
============

https://liangzou.blogspot.com/2019/06/how-to-setup-eclipse-pydev-to-run-yapf.html

Enable pydev checking: Preferences | Spelling Add User defined dictionary: /home/liangzou/eclipse-workspace/user-dict.txt
Then click on the word that eclipse doesn't recognize, press ctrl + 1, then use up/down key and enter to select the options.

Setup Go Editor
===========

Need to disable AnyEdit Tools (Format some code on save if that editor doesn't support)






Setup Text Editor
=============
Show white spaces



Change the Transparency level to 255