Commit Graph

99 Commits

Author SHA1 Message Date
Allan Odgaard
c2397484b8 Use C++11 for loop
Majority of the edits done using the following ruby script:

    def update_loops(src)
      dst, cnt = '', 0

      block_indent, variable = nil, nil
      src.each_line do |line|
        if block_indent
          if line =~ /^#{block_indent}([{}\t])|^\t*$/
            block_indent = nil if $1 == '}'
            line = line.gsub(%r{ ([^a-z>]) \(\*#{variable}\) | \*#{variable}\b | \b#{variable}(->) }x) do
              $1.to_s + variable + ($2 == "->" ? "." : "")
            end
          else
            block_indent = nil
          end
        elsif line =~ /^(\t*)c?iterate\((\w+), (?!diacritics::make_range)(.*\))$/
          block_indent, variable = $1, $2
          line = "#$1for(auto const& #$2 : #$3\n"
          cnt += 1
        end
        dst << line
      end
      return dst, cnt
    end

    paths.each do |path|
      src = IO.read(path)

      cnt = 1
      while cnt != 0
        src, cnt = update_loops(src)
        STDERR << "#{path}: #{cnt}\n"
      end

      File.open(path, "w") { |io| io << src }
    end
2014-03-03 10:34:13 +07:00
Allan Odgaard
be92d71c46 Allow disabling indent corrections when typing on empty lines
This is generally desired when the indent of a new line does not (necessarily) depend on lines above it, but where we otherwise do want indent corrections, e.g. HTML.
2014-03-02 20:06:31 +07:00
Allan Odgaard
4e1cdb4c9e Snippets with overlapping fields could cause multiple carets
For example in ruby inserting ‘env⇥’, deleting the initially selected letter, and typing B or S, would insert an additional caret (it was actually inserted in the previous step, but not visible since it was overlapping the existing caret).

The API lack proper support for returning the new caret range so we are using a heuristic to figure out which of the returned ranges correspond to our caret. Ideally the API would be updated.
2014-02-26 08:29:42 +07:00
Allan Odgaard
56a906a0ac Use temporary pasteboards when replaying macros
This applies to search, replace, and (unless disabled) regular pasteboard.
2014-02-20 22:22:55 +07:00
Allan Odgaard
aec82de6e2 Implement kReplace / kReplaceAndFind actions
These are used when replaying macros.
2014-02-20 22:09:36 +07:00
Allan Odgaard
17dca05dba Let editor_t remember (regexp) captures from editor_t::find 2014-02-20 22:09:36 +07:00
Allan Odgaard
aff813203b Find macro actions now populate the search/replace pasteboard
This should be consistent with TextMate 1.x and is required for the replace actions.
2014-02-20 22:09:36 +07:00
Allan Odgaard
16c7679c0a Use ng::word_at for what to complete
This way we won’t try to complete whitespace.
2014-02-12 20:08:41 +07:00
Allan Odgaard
3b760492a8 Do not set TM_CURRENT_WORD if caret is surrounded by whitespace
This is consistent with “word” as input for commands.
2014-02-11 20:56:38 +07:00
Allan Odgaard
da31c2d11a Introduce ng::word_at (refactoring) 2014-02-11 20:55:01 +07:00
Allan Odgaard
c54c2c89f2 Only set TM_CURRENT_WORD when we have a word 2014-02-11 20:47:01 +07:00
Allan Odgaard
dd5c050f28 Commands taking “word” as input will not get whitespace as input
Previously if there was whitespace to the left and right of the caret, the entire sequence of whitespace was given as input to the command. This was not the case for TextMate 1.x so it broke the format commands in the LaTeX bundle (bold, italic, and teletype).
2014-02-01 21:19:22 +07:00
Allan Odgaard
0d17cc731f Handle CRLF delimited clipboard data 2013-10-31 18:32:16 +01:00
Allan Odgaard
8c16b160e0 Improve “replace input” command output for column selections
The output will be inserted corresponding to the subsets selected on each line.

If the output has less lines than the column selection then the additional selected lines are cleared.

If the output has more lines than the column selection then the additional output lines are dropped.
2013-10-20 22:29:53 +02:00
Allan Odgaard
3064fb82b4 Change text::range_t → ng::range_t 2013-10-20 19:10:02 +02:00
Allan Odgaard
adb2741689 Remove non-UTF-8 from clipboard data
It should be safe to assume that clipboard data is valid UTF-8, but I’m seeing crashes related to creating a CFString (from buffer content) after a paste operation, so the assumption might not be valid.
2013-10-08 21:59:55 +02:00
Allan Odgaard
b45e52ae71 Remove non-UTF-8 from command output
Previously we would create a hex dump from the output.
2013-10-08 21:59:55 +02:00
Allan Odgaard
4d37803f5c Remove non-UTF-8 from completion command output
Previously an entire line containing non-UTF-8 would be discarded, now we only remove the problematic bytes.
2013-10-08 21:59:54 +02:00
Allan Odgaard
b8bccf684b Fix re-indented paste with zig-zap selections
When selecting multiple lines, but not including the newline on the last line of the selection, TextMate still consider it a “full line” and will insert a newline when pasting, unless pasting on an empty line.

Previously the check to see if the line was empty, would not account for a non-empty but selected line, which would effectively be empty since the selected text is deleted before pasting.
2013-10-04 22:02:56 +02:00
Allan Odgaard
4363a27897 Source bash_init.sh for code in snippets that have no shebang
This is consistent with TextMate 1.x behavior.

Fixes ruby.tmbundle#56
2013-10-04 16:51:27 +02:00
Allan Odgaard
1c308c810d Use map::emplace instead of inserting std::pair (C++11) 2013-09-05 20:59:11 +02:00
Allan Odgaard
e4e80a946c Use std::make_shared 2013-09-03 12:27:20 +02:00
Allan Odgaard
62db7aff11 Add comparison operators to what’s understood by ⌃T 2013-08-26 11:26:56 +02:00
Allan Odgaard
695ff4c703 Improve the “swap” functionality of ⌃T
See tests for details.
2013-08-24 20:28:16 +02:00
Allan Odgaard
bf1e92b865 Do not use global constructors for fixtures 2013-08-16 22:40:08 +02:00
Allan Odgaard
e9576e60f9 Let transpose detect and swap words
The detection is done by a regexp match of ‘\w+\W+\w+’ allowing the string to optionally be wrapped in round, square, or squiggly parentheses.
2013-08-09 23:13:58 +02:00
Allan Odgaard
2bdea516e3 Avoid multiple carets after a “replace all”
If using folder search and replacements were done in an open document, then a caret would previously appear after each replacement.
2013-07-27 16:30:02 +02:00
Allan Odgaard
98585e166e Use byte range for replacement API 2013-07-27 16:30:02 +02:00
Allan Odgaard
6718a8a32c Use libdispatch for threaded write to pipe 2013-07-26 23:09:14 +02:00
Allan Odgaard
6a4c0ff379 Update testing system for editor framework 2013-07-25 11:52:07 +02:00
Allan Odgaard
570afce039 Reformat and justify was broken for multi-paragraph input
Fixes #1021.
2013-06-18 11:44:47 +07:00
Allan Odgaard
3db66d1a05 Support “Find Previous” in macros 2013-06-15 16:06:43 +07:00
Allan Odgaard
9dd653a3e7 Ignore non-UTF-8 completion command results 2013-05-26 17:27:44 +08:00
Allan Odgaard
6a9b0374ed Sanitize non-UTF-8 command output
We now convert the output to a hex-dump incase it is not valid UTF-8. Ideally we would present the user with a dialog, but for now a hex-dump will do and prevents a potential crash.
2013-05-26 17:26:06 +08:00
Allan Odgaard
b6fce5fe30 Check if command result is valid UTF-8
This was previously implicit by using oak::command_t
2013-05-16 21:36:43 +07:00
Allan Odgaard
714779d89b Use io::spawn instead of oak::command_t with snippets
Since we now run the shell code directly (via ‘/bin/sh -c «command»’) we no longer source ‘TM_SUPPORT_PATH/lib/bash_init.sh’.

I don’t think any code embedded in snippets rely on things setup by this file, but if they do, I’d prefer we update the snippets to explicitly source the file.
2013-05-16 21:36:00 +07:00
Allan Odgaard
598c3b7a89 Allow completion commands to have requirements 2013-05-15 22:58:06 +07:00
Allan Odgaard
e3bc6e982b Introduce editor_delegate_t
This is to avoid having editor_t hold a document_t.
2013-05-15 22:38:02 +07:00
Allan Odgaard
ce4ae62547 Change ‘variables_for_path’ API
We now accept the a directory in addition to the path. If a directory is provided, the path is only used to filter variables rooted at the directory.
2013-05-12 11:09:18 +07:00
Allan Odgaard
8b3f05485d Change argument ordering for ‘scope_variables’
Generally we should always provide a base environment, since the scoped variables are format strings. The filtering scope selector is however optional, and we do not have one when executing commands outside an fi;e/editor context.
2013-05-12 11:09:17 +07:00
Allan Odgaard
4a32881c11 Remove legacy variable functions 2013-05-12 11:09:17 +07:00
Allan Odgaard
1d1ce8e234 Explicit variable setup for completion commands 2013-05-12 11:09:16 +07:00
Allan Odgaard
a6cf964e9f Remove callback support from document::run 2013-05-12 11:09:16 +07:00
Allan Odgaard
ccf2414768 Add pwd argument to command runner
Previously this was only possible to change by setting PWD in the passed-in environment.
2013-05-12 11:09:15 +07:00
Allan Odgaard
7f4649ba32 Factor out deprecated variable collecting 2013-05-12 11:09:15 +07:00
Allan Odgaard
5fd188531a Change naming of functions for obtaining variables
These are now all prefixed with what they are obtaining variables for (scope, document, bundle, …) which makes it easier to analyze/refactor the code.

Also change document_t’s settings function to document_settings.
2013-05-09 15:16:32 +07:00
Allan Odgaard
28306cb048 Disable “smart tab” for discontinuous/column selections 2013-04-27 13:21:32 +07:00
Allan Odgaard
7f933bfc57 Disable auto-pairing when recording macros
Since auto-pairing can be adjusted via user customization we disable it for both macro recording and replay. Old macros will need to be updated (but this was already the case, as 2.0 never did pairing as part of replay).

A better solution is to record each implicit action of the auto-pairing in the macro. This can however be added later without breaking existing macros, as the macro player will remain the same.

Closes #130.
2013-04-10 10:13:01 +07:00
Allan Odgaard
34bf85d8d1 Remove whitespace when shifting text left
Previously shifting text left/right would ignore blank lines (as noted in issue #419).

When shifting left though it does make sense to delete whitespace, especially as the same code is used to re-indent when pasting.

Fixes #810.
2013-03-13 12:38:12 +01:00
Allan Odgaard
0075b46c82 Introduce zeroIndentPattern
This will give the matched lines zero indent but without affecting the following lines.

Probably the only use-case for this is C preprocessor directives.
2013-03-13 12:38:12 +01:00