itom  4.1.0
pyAutoIndent.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom.
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  itom is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17  General Public Licence for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with itom. If not, see <http://www.gnu.org/licenses/>.
21 
22  Further hints:
23  ------------------------
24 
25  This file belongs to the code editor of itom. The code editor is
26  in major parts a fork / rewritten version of the python-based source
27  code editor PyQode from Colin Duquesnoy and others
28  (see https://github.com/pyQode). PyQode itself is licensed under
29  the MIT License (MIT).
30 
31  Some parts of the code editor of itom are also inspired by the
32  source code editor of the Spyder IDE (https://github.com/spyder-ide),
33  also licensed under the MIT License and developed by the Spyder Project
34  Contributors.
35 
36 *********************************************************************** */
37 
38 #ifndef PYAUTOINDENT_H
39 #define PYAUTOINDENT_H
40 
41 /*
42 Contains python smart indent modes
43 */
44 
45 #include "autoindent.h"
46 #include "../utils/utils.h"
47 
48 #include <qtextcursor.h>
49 #include <qstring.h>
50 #include <qregularexpression.h>
51 
52 namespace ito {
53 
54 
55 /*
56 Automatically indents text, respecting the PEP8 conventions.
57 
58 Customised :class:`pyqode.core.modes.AutoIndentMode` for python
59 that tries its best to follow the pep8 indentation guidelines.
60 */
62 {
63  Q_OBJECT
64 public:
65  PyAutoIndentMode(const QString &description = "", QObject *parent = NULL);
66  virtual ~PyAutoIndentMode();
67 
68  virtual void onInstall(CodeEditor *editor);
69 
70 private slots:
71 
72 protected:
73  virtual QPair<QString, QString> getIndent(const QTextCursor &cursor) const;
74 
75  QPair<QString, QString> handleIndentBetweenParen(int column, const QString &line, const QPair<QString, QString> &parent_impl, const QTextCursor &cursor) const;
76  void handleIndentInsideString(const QChar &c, const QTextCursor &cursor, const QString &fullline, QString &post, QString &pre) const;
77  QString handleNewScopeIndentation(const QTextCursor &cursor, const QString &fullline) const;
78  void handleIndentInStatement(const QString &fullline, const QString &lastword, QString &post, QString &pre) const;
79  void handleIndentAfterParen(const QTextCursor &cursor, QString &post) const;
80  bool betweenParen(const QTextCursor &cursor, int column) const;
81  QPair<int, QChar> getFirstOpenParen(const QTextCursor &tc, int column) const;
82  void getParenPos(const QTextCursor &cursor, int column, int &ol, int &oc, int &cl, int &cc) const;
83  void parensCountForBlock(int column, const QTextBlock &block, int &numOpenParentheses, int &numClosedParentheses) const;
84  int getIndentOfOpeningParen(const QTextCursor &cursor) const;
85  bool checkKwInLine(const QStringList &kwds, const QString &lparam) const;
86 
87  static QPair<bool, QChar> isInStringDef(const QString &fullline, int column);
88  static bool isParenOpen(const Utils::ParenthesisInfo &paren);
89  static bool isParenClosed(const Utils::ParenthesisInfo &paren);
90  static QString getFullLine(const QTextCursor &cursor);
91  static QString getLastWordUnstripped(const QTextCursor &cursor);
92  static QString getLastWord(const QTextCursor &cursor);
93  static QChar getPrevChar(const QTextCursor &cursor);
94  static QChar getNextChar(const QTextCursor &cursor);
95  static bool atBlockEnd(const QTextCursor &cursor, const QString &fullline);
96  static bool atBlockStart(const QTextCursor &cursor, const QString &line);
97 
98  static QStringList newScopeKeywords;
99 
100 };
101 
102 } //end namespace ito
103 
104 #endif
Definition: codeEditor.h:110
Definition: autoindent.h:75
Definition: utils.h:54
Definition: apiFunctionsGraph.cpp:39
Definition: pyAutoIndent.h:61