diff --git a/CHANGELOG b/CHANGELOG
index 335e9b9..de6228d 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,8 +1,22 @@
Diakonos Changelog
------------------
+0.8.11
+
+Contributors: Pistos, dominikh
+
+- Added join_lines_upward (Alt-Shift-J).
+- Added one-key selection in buffer list.
+- Added support for single line indentation.
+- Added extension system.
+- Added surround_selection and related functions.
+- Added "about" page.
+- Various bug fixes and refactorings.
+
0.8.10
+Contributors: Pistos, dominikh
+
- Ruby version 1.9+ now required. (Ruby 1.8 support dropped)
- Added go_to_char (Alt-N).
- Added go_to_char_previous (Alt-P).
@@ -23,6 +37,8 @@ Diakonos Changelog
0.8.9
+Contributors: Pistos, Decklin Foster
+
- Put interaction timer only on first stale session prompt, not any after that.
- Changed all function names from camelCase to snake_case.
- Added --help-dir switch to installer.
@@ -31,7 +47,6 @@ Diakonos Changelog
- Fixed a line number display bug.
- X windows pasting handled much better now.
- Numerous internal refactorings and reorganizations.
-- Accepted patches from Decklin Foster.
0.8.8
diff --git a/LICENSE b/LICENSE
new file mode 120000
index 0000000..97ea633
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1 @@
+LICENCE
\ No newline at end of file
diff --git a/README b/README
index 094da0e..6a2b021 100644
--- a/README
+++ b/README
@@ -1,9 +1,6 @@
-Diakonos
+= Diakonos
-========
-
-REQUIREMENTS
-============
+== REQUIREMENTS
- Ruby 1.9+
@@ -11,8 +8,7 @@ Diakonos is built to run on Linux, but may run under other flavours of UNIX.
It is known NOT to work under Windows (unless using Cygwin).
-DOWNLOAD
-========
+== DOWNLOAD
The latest stable tarballs can be acquired from
@@ -23,8 +19,7 @@ The latest development code can be obtained from github:
git clone git://github.com/Pistos/diakonos.git
-INSTALLATION
-============
+== INSTALLATION
ruby install.rb --help
ruby install.rb [installation parameters]
@@ -34,14 +29,12 @@ places like /usr . However, Diakonos runs perfectly well in userspace, such
as under ~/usr .
-UNINSTALLATION
-==============
+== UNINSTALLATION
diakonos --uninstall
-USAGE
-=====
+== USAGE
Run with any of these:
@@ -61,8 +54,9 @@ use the interactive help system.
The source code repository is at http://github.com/Pistos/diakonos/tree/master .
-Send comments, feedback and tech support requests to
-irc.freenode.net:6667#mathetes or http://linis.purepistos.net .
+Send comments, feedback and tech support requests to the #mathetes channel on
+the FreeNode IRC network ( http://webchat.freenode.net/?channels=mathetes ),
+or http://linis.purepistos.net .
Pistos
http://purepistos.net/diakonos
diff --git a/diakonos.conf b/diakonos.conf
index 78d075c..0c18453 100644
--- a/diakonos.conf
+++ b/diakonos.conf
@@ -116,7 +116,7 @@ fuzzy_file_find false
# Use "% syntax" as placeholders
# e.g. %d for decimal integers, %s for strings
-status.left -- %s %s%s%s%s -- (%s) --%s
+status.left -- %s %s%s%s%s -- (%s) --
status.right - %s Buf %d of %d --- L%3d/%3d C%2d --
# The string to use to fill in the space between the left and right sides
# of the status line.
@@ -127,8 +127,7 @@ status.unnamed_str (unnamed file)
status.read_only_str (read-only)
# status.vars: any subset of:
# line row num_lines col filename modified type buffer_number num_buffers selecting selection_mode session_name read_only
-status.vars filename modified read_only selecting selection_mode type @git_branch session_name buffer_number num_buffers row num_lines col
-#status.vars filename modified read_only selecting selection_mode type @git_branch buffer_number num_buffers row num_lines col
+status.vars filename modified read_only selecting selection_mode type session_name buffer_number num_buffers row num_lines col
status.format inverse
# ---------------------------------------------------------------------
@@ -285,7 +284,8 @@ key keycode353 unindent
#key tab insertSpaces 4
#key tab insertTab
key ctrl+t insertTab
-key alt+j joinLines
+key alt+j join_lines
+key esc J join_lines_upward
key f1 help
key esc O P help
@@ -294,8 +294,8 @@ key esc [ [ A help
key f13 help
key esc O 2 P help
key esc O 1 ; 2 P help
-key f11 loadConfiguration
-key esc [ 2 3 ~ loadConfiguration
+key f11 about
+key esc [ 2 3 ~ about
key f12 openFile "~/.diakonos/diakonos.conf"
key esc [ 2 4 ~ openFile "~/.diakonos/diakonos.conf"
# Option-F12 in OSX
@@ -410,7 +410,6 @@ key esc [ 1 ; 2 evaluate
key ctrl+alt+c shell "ruby -c $f"
#key f10 spawn "firefox --display=:0 http://apidock.com/ruby/$i"
#key f10 spawn "DISPLAY=:0 opera --remote 'openURL(http://www.ruby-doc.org/core-1.9/classes/$i.html,new-page)' 2>&1 > /dev/null"
-key f9 shell "cd $d; git diff --ignore-space-change -- $f", 'git.diff'
# To use the following:
# 1) Copy to the clipboard some Ruby code which operates on stdin text and outputs to stdout.
@@ -479,6 +478,21 @@ lang.all.tokens.conflict_theirs ^>>>>>>>.*
lang.all.tokens.conflict_theirs.format 15 bold
lang.all.tokens.conflict_separator ^=======$
lang.all.tokens.conflict_separator.format 9 bold
+# lang.all.tokens.trailing_whitespace (\s+$)
+# lang.all.tokens.trailing_whitespace.format 9
+lang.all.surround.pair "(" "( " " )"
+lang.all.surround.pair ")" "(" ")"
+lang.all.surround.pair "{" "{ " " }"
+lang.all.surround.pair "}" "{" "}"
+lang.all.surround.pair "[" "[ " " ]"
+lang.all.surround.pair "]" "[" "]"
+lang.all.surround.pair "<" "< " " >"
+lang.all.surround.pair ">" "<" ">"
+lang.all.surround.pair "'" "'" "'"
+lang.all.surround.pair "\"" "\"" "\""
+lang.all.surround.pair "/*" "/*" "*/"
+
+
# Inherited by several languages
@@ -528,6 +542,7 @@ lang.dhf.indent.auto true
lang.dhf.indent.roundup true
lang.dhf.wrap_margin 80
+
# XML
lang.xml.filemask \.(xml|xsl|rdl|aiml)$
@@ -581,6 +596,8 @@ lang.xml_comment.indent.size 2
lang.xml_comment.indent.auto true
lang.xml_comment.indent.roundup true
#lang.xml_comment.indent.using_tabs true
+lang.xml.surround.pair "<!--" "<!-- " " -->"
+lang.xml.surround.pair "/^<(.+?)>$/" "<\1>" "</\1>"
lang.html.filemask \.([rx]?html?|php|asp|erb)$
lang.html.format.default white
@@ -649,6 +666,8 @@ lang.html_comment.indent.size 4
lang.html_comment.indent.auto true
lang.html_comment.indent.roundup true
#lang.html_comment.indent.using_tabs true
+lang.html.surround.pair "<!--" "<!-- " " -->"
+lang.html.surround.pair "/^<(.+?)>$/" "<\1>" "</\1>"
# CSS
@@ -761,6 +780,7 @@ lang.ruby.indent.ignore ^\s*$
lang.ruby.context.ignore ^=(begin|end)$
lang.ruby.column_delimiters =>?|:|,
+
# PHP
lang.php.filemask \.php\d?$
@@ -851,6 +871,7 @@ lang.perl.indent.ignore ^\s*$
lang.perl.context.ignore ^(.+:|\s*\{?)$
lang.perl.column_delimiters =>?|:|,
+
# Python
lang.python.filemask \.py$
@@ -949,6 +970,7 @@ lang.c.indent.size 4
lang.c.indent.auto true
lang.c.indent.roundup false
#lang.c.indent.using_tabs true
+lang.c.indent.indenters_next_line (if\s*\(.+?\)\s*[^{]?$)
lang.c.indent.indenters (case|[{\[(]$)
lang.c.indent.unindenters (case|^\s+[\]})])
lang.c.indent.preventers (\".+?[^\\]\")|('.+?[^\\]')|(\/\/.*)
@@ -1114,7 +1136,6 @@ lang.diff.tokens.diff_command (^diff .+$)
lang.diff.tokens.diff_command.format 13 bold
lang.yaml.filemask (?:\.ya?ml)$
-lang.yaml.bangmask ^---(?:.[^/]|$)
lang.yaml.format.default white bold
lang.yaml.format.selection inverse
lang.yaml.format.found yellow inverse
@@ -1357,7 +1378,6 @@ lang.haskell.indent.ignore ^\s*$
# lang.haskell.context.ignore ^=(begin|end)$
lang.haskell.column_delimiters =>?|:|,
-
# Custom configuration files can be included.
# If a setting is specified again, it overrides the previous setting given
# higher up in the configuration file(s).
diff --git a/diakonos.gemspec b/diakonos.gemspec
index 1bd2c18..481f5fd 100755
--- a/diakonos.gemspec
+++ b/diakonos.gemspec
@@ -4,7 +4,7 @@ require 'rubygems'
spec = Gem::Specification.new do |s|
s.name = 'diakonos'
- s.version = '0.8.10'
+ s.version = '0.8.11'
s.summary = 'A usable console-based text editor.'
s.description = 'Diakonos is a customizable, usable console-based text editor.'
s.homepage = 'http://purepistos.net/diakonos'
@@ -24,11 +24,11 @@ Dear RubyGems administrator:
As of version 0.8.8, Diakonos is no longer installed via RubyGems. You may
find that a Diakonos package is already available for your operating system's
package manager. There are packages for: Ubuntu, Debian, Gentoo, Arch Linux,
-Slackware, and Sourcemage.
+Slackware, Sourcemage, and possibly more.
If there is no package for your system, you can install Diakonos manually:
-- Uninstall any previously installed diakonos gems
+- Uninstall any previously installed diakonos gems (including this one)
- Acquire a tarball from http://purepistos.net/diakonos
- Unpack the tarball
- ruby install.rb --help
diff --git a/extensions/dk-hello-world/hello-world.conf b/extensions/dk-hello-world/hello-world.conf
new file mode 100644
index 0000000..4333a74
--- /dev/null
+++ b/extensions/dk-hello-world/hello-world.conf
@@ -0,0 +1 @@
+key f23 hello_world
diff --git a/extensions/dk-hello-world/hello-world.rb b/extensions/dk-hello-world/hello-world.rb
new file mode 100644
index 0000000..d966ebc
--- /dev/null
+++ b/extensions/dk-hello-world/hello-world.rb
@@ -0,0 +1,9 @@
+module Diakonos
+ module Functions
+
+ def hello_world
+ @current_buffer.paste "Hello, world!"
+ end
+
+ end
+end
\ No newline at end of file
diff --git a/extensions/dk-hello-world/info.yaml b/extensions/dk-hello-world/info.yaml
new file mode 100644
index 0000000..63f7673
--- /dev/null
+++ b/extensions/dk-hello-world/info.yaml
@@ -0,0 +1,31 @@
+name: Hello World
+description: An example of a Diakonos extension
+author:
+ name: Pistos
+ email: somebody@example.com
+ uri: http://blog.purepistos.net
+version: 1.0.0
+uris:
+ homepage: http://github.com/Pistos/diakonos/tree/master/extensions/dk-hello-world
+ repository: git://github.com/Pistos/diakonos.git
+licence: MIT
+requirements:
+ diakonos:
+ minimum: 0.8.11
+ tested:
+ - 0.8.11
+ gems:
+ # - gemname:
+ # minimum: 1.0.0
+ # tested:
+ # - 1.0.0
+ # - 1.1.0
+ # - gemname:
+ # minimum: 1.0.0
+ # tested:
+ # - 1.0.0
+ # - 1.1.0
+notes: >
+ This extension adds a hello_world function to Diakonos.
+
+ Pressing Shift-F11 will activate the function.
diff --git a/help/config.dhf b/help/config.dhf
index d0a806e..4a1a46b 100644
--- a/help/config.dhf
+++ b/help/config.dhf
@@ -42,9 +42,11 @@ include ~/.diakonos/extra.conf
If a setting is specified again (whether in the same file, or an included
file), it overrides the previous setting given higher up in the configuration
-file(s). Note that editing and saving custom configuration files will not
-cause the changes to be automatically loaded like they are with the default
-configuration file. To reload all configuration files, press <F11>.
+file(s). Note that editing and saving custom configuration files which reside
+outside of ~/.diakonos will not cause the changes to be automatically loaded
+like they are with configuration files in ~/.diakonos. To reload all
+configuration files, quit and restart Diakonos, or press <Shift-F2> and type
+"load_configuration".
## Configuration inheritance
diff --git a/help/extensions.dhf b/help/extensions.dhf
new file mode 100644
index 0000000..f4f659d
--- /dev/null
+++ b/help/extensions.dhf
@@ -0,0 +1,124 @@
+# Extending Diakonos
+
+Diakonos has a simple but powerful extension system. Extensions are written in
+Ruby (http://www.ruby-lang.org).
+
+
+## Installing and Uninstalling Extensions
+
+### Unpack/Clone
+
+Extensions are installed in ~/.diakonos/extensions/. Each extension should
+have its own subdirectory under there. Extension tarballs or repository clones
+should be unpacked or cloned under there.
+
+### Load
+
+Once an extension is installed into ~/.diakonos/extensions/, you activate it
+by adding a command to your configuration:
+
+ load_extension name_of_the_extension
+
+Diakonos will load extensions at startup, and will reload extensions whenever
+the Diakonos configuration is updated.
+
+### Unload
+
+To deactivate an extension, simply remove (or comment out) all load_extension
+directives from your configuration which load the extension.
+
+### Uninstall
+
+Extensions can be removed cleanly by deleting the extension's subdirectory out
+of ~/.diakonos/extensions/.
+
+
+## Extension Format
+
+### Directory Structure
+
+A Diakonos extension consists of a directory (or directory tree) of files:
+
+ info.yaml
+ *.conf
+ *.rb
+
+The simplest extension will have nothing but an info.yaml file. This "empty"
+extension will do nothing useful, though, of course.
+
+Diakonos will parse and load all configuration files (*.conf) in the root of
+the extension's directory. All Ruby files (*.rb) found in the extension's
+directory, or any subdirectory underneath it, are loaded and executed at
+startup, and on configuration change. Typically, an extension will only have
+one configuration file, but it may have any number of Ruby files.
+
+### Information File
+
+To be valid, an extension must have a properly-formatted info.yaml file. As
+the filename suggests, info.yaml is a YAML file. It consists of several keys,
+and a few arrays, described below.
+
+The diakonos key is required. It is strongly recommended to have name, uris
+and version keys. The other keys are optional.
+
+name: (recommended) The name of the extension.
+
+description: (optional) A brief, one-line description of the extension.
+
+author: (optional) Several subkeys provide information about the extension's author.
+ name: The author's name or nickname.
+ email: The author's email address.
+ uri: A URI associated with the author. This might be a homepage, or a blog.
+
+version: (recommended) The version of the extension.
+
+uris: (recommended)
+ homepage: The website giving more information about the extension.
+ repository: The URI of the extension's source code repository. This should
+ be a URI that can be used with version control software, and so might
+ begin with "svn://" or "git://".
+
+licence: (optional) The licence of the extension's source code.
+
+requirements: (required) Several subkeys tell diakonos about what versions of
+ things the extension works with.
+ diakonos: (required) Several subkeys tell Diakonos about what versions of
+ Diakonos the extension works with.
+ minimum: The minimum version of Diakonos required for the extension to
+ function properly.
+ tested: A list of Diakonos versions which the extension is known to run
+ under.
+ gems: (optional) If the extension needs any gems to function, they should be
+ listed here, with their minimum and tested versions given.
+
+notes: (optional) Longer text describing the extension, its capabilities and
+ its usage. For multiple paragraphs, use the YAML syntax "notes: >", and
+ indent the paragraphs to the same level.
+
+
+## Extension Code
+
+Extension code is any valid Ruby code. See http://purepistos.net/diakonos/rdoc/
+for source code documentation for Diakonos, and
+http://github.com/Pistos/diakonos/tree/master/extensions/dk-hello-world for an
+example of an extension.
+
+To have code execute on keypress, define a method in the Diakonos::Functions
+module. All methods in Diakonos::Functions are exposed to the keying system,
+any method name can be referred to by the key directive in configuration files.
+
+Methods of Diakonos::Functions are run within the context of the main
+::Diakonos::Diakonos object. In this context, you get access to all of the
+instance variables. Some variables of note:
+
+ @current_buffer
+ @diakonos_home String containing the user's Diakonos dir (usually ~/.diakonos)
+ @buffers A BufferHash holding all the open buffers
+ @status_vars
+ @settings A Hash containing all settings from all configuration files
+
+When not within a method of Diakonos::Functions, main ::Diakonos::Diakonos
+object can be referred to by using the global variable $diakonos.
+
+
+Tags: script scripts scripting program programming language ruby extend extension extensions plugin plug-in plugins plug-ins addon addons add-on add-ons package packages format layout structure load loading unload unloading activate deactivate activating deactivating install installing installation
diff --git a/help/scripting.dhf b/help/scripting.dhf
index bb4a3df..d4fada6 100644
--- a/help/scripting.dhf
+++ b/help/scripting.dhf
@@ -28,7 +28,7 @@ Press <F7> to iterate over each line of selected text. You will be prompted
for Ruby code which will act as the body of a Ruby block which uses the
variable "line" and evaluates to a String. For example:
- line.strip.squeeze( ' ' )
+ line.strip.squeeze( ' ' )
will strip off whitespace from the beginning and end of each line and then
collapse all consecutive sequences of spaces into single spaces.
@@ -40,12 +40,12 @@ will be prompted for Ruby code which operates on the array variable "lines".
For example:
lines.find_all { |l| /foo/ === l }
-
+
will replace the selected lines with the lines that match the regular expression
/foo/.
lines.sort
-
+
will sort the selected lines.
## Startup Scripts
@@ -61,6 +61,8 @@ to initiate a search on startup:
diakonos -e 'find "down", CASE_SENSITIVE, "search expression"' filename
+See also the documentation on extensions.
+
## Hooks
Diakonos provides a means for you to execute arbitrary Ruby code when certain
diff --git a/help/support.dhf b/help/support.dhf
index f7ec347..fabf86f 100644
--- a/help/support.dhf
+++ b/help/support.dhf
@@ -2,9 +2,9 @@
You can chat about Diakonos in the #mathetes channel of the FreeNode IRC
network. If you don't have an IRC client, or don't know what IRC is, you can
-direct your web browser to
+direct your web browser to
- http://mibbit.com/?server=irc.freenode.net&channel=%23mathetes
+ http://webchat.freenode.net/?channels=mathetes
Go to the IRC channel for technical support, or to give feedback and commentary
about Diakonos. It's the place go for bug reports, feature requests and tech
diff --git a/help/welcome.dhf b/help/welcome.dhf
index 9056ae2..f2a6496 100644
--- a/help/welcome.dhf
+++ b/help/welcome.dhf
@@ -7,7 +7,7 @@ I have crafted Diakonos with ease of use in mind, so I hope you find it the
most easy-to-use console text editor available for Linux. If you have any
suggestions, questions or comments, please share your thoughts in the #mathetes
channel of the FreeNode IRC network
-( http://mibbit.com/?server=irc.freenode.net&channel=%23mathetes ).
+( http://webchat.freenode.net/?channels=mathetes ).
## Getting Started
@@ -30,4 +30,4 @@ save your change.
-Tags: diakonos welcome intro introduction getting started starting new newb newbie remove message
\ No newline at end of file
+Tags: diakonos welcome intro introduction getting started starting new newb newbie remove message
diff --git a/lib/diakonos.rb b/lib/diakonos.rb
index 8aecbdb..98613ce 100755
--- a/lib/diakonos.rb
+++ b/lib/diakonos.rb
@@ -34,6 +34,9 @@ require 'diakonos/sized-array'
require 'diakonos/version'
require 'diakonos/installation'
+
+require 'diakonos/about'
+require 'diakonos/buffer-management'
require 'diakonos/config'
require 'diakonos/functions'
require 'diakonos/functions/basics'
@@ -53,14 +56,13 @@ require 'diakonos/functions-deprecated'
require 'diakonos/help'
require 'diakonos/display'
require 'diakonos/display/format'
-require 'diakonos/interaction'
+require 'diakonos/grep'
require 'diakonos/hooks'
+require 'diakonos/interaction'
require 'diakonos/keying'
require 'diakonos/logging'
require 'diakonos/list'
-require 'diakonos/buffer-management'
require 'diakonos/sessions'
-require 'diakonos/grep'
require 'diakonos/text-mark'
require 'diakonos/bookmark'
@@ -79,6 +81,8 @@ require 'diakonos/buffer/undo'
require 'diakonos/clipboard'
require 'diakonos/clipboard-klipper'
require 'diakonos/clipboard-xclip'
+require 'diakonos/extension'
+require 'diakonos/extension-set'
require 'diakonos/readline'
require 'diakonos/vendor/fuzzy_file_finder'
@@ -110,7 +114,7 @@ module Diakonos
class Diakonos
attr_reader :diakonos_home, :script_dir, :clipboard,
- :list_filename, :hooks, :indenters, :unindenters, :closers,
+ :list_filename, :hooks, :indenters, :indenters_next_line, :unindenters, :closers,
:last_commands, :there_was_non_movement, :do_display, :testing
include ::Diakonos::Functions
@@ -120,6 +124,7 @@ module Diakonos
mkdir @diakonos_home
@script_dir = "#{@diakonos_home}/scripts"
mkdir @script_dir
+ @extensions = ExtensionSet.new( File.join( @diakonos_home, 'extensions' ) )
initialize_session
@files = Array.new
@@ -129,11 +134,12 @@ module Diakonos
init_help
- @debug = File.new( "#{@diakonos_home}/debug.log", 'w' )
- @list_filename = @diakonos_home + '/listing.txt'
- @diff_filename = @diakonos_home + '/text.diff'
- @help_filename = "#{@help_dir}/about-help.dhf"
- @error_filename = "#{@diakonos_home}/diakonos.err"
+ @debug = File.new( File.join( @diakonos_home, 'debug.log' ), 'w' )
+ @list_filename = File.join( @diakonos_home, 'listing.txt' )
+ @diff_filename = File.join( @diakonos_home, 'text.diff' )
+ @help_filename = File.join( @help_dir, 'about-help.dhf' )
+ @error_filename = File.join( @diakonos_home, 'diakonos.err' )
+ @about_filename = File.join( @diakonos_home, 'about.dhf' )
@win_main = nil
@win_context = nil
@@ -284,7 +290,9 @@ module Diakonos
session_buffers = session_startup
session_buffer_number = @session[ 'current_buffer' ] || 1
- Dir[ "#{@script_dir}/*" ].each do |script|
+ scripts = @extensions.scripts + Dir[ "#{@script_dir}/*" ]
+ debug_log "scripts: #{scripts.inspect}"
+ scripts.each do |script|
begin
require script
rescue Exception => e
@@ -297,6 +305,7 @@ module Diakonos
)
end
end
+
@hooks.each do |hook_name, hook|
hook.sort { |a,b| a[ :priority ] <=> b[ :priority ] }
end
diff --git a/lib/diakonos/about.rb b/lib/diakonos/about.rb
new file mode 100644
index 0000000..97ebca9
--- /dev/null
+++ b/lib/diakonos/about.rb
@@ -0,0 +1,55 @@
+module Diakonos
+ class Diakonos
+
+ def about_write
+ File.open( @about_filename, "w" ) do |f|
+ inst = ::Diakonos::INSTALL_SETTINGS
+
+ ext_loaded = @extensions.loaded_extensions.sort_by { |e|
+ e.name.downcase
+ }.map { |e|
+ %{
+### #{e.name} #{e.version}
+#{e.description}
+ }.strip
+ }.join( "\n\n" )
+
+ ext_not_loaded = @extensions.not_loaded_extensions.sort.map { |e|
+ "### #{e} (NOT LOADED)"
+ }.join( "\n" )
+
+ f.puts %{
+# About Diakonos
+
+Licence: MIT Licence
+Copyright: Copyright (c) 2004-#{ Time.now.year } Pistos
+
+## Version
+
+Version: #{ ::Diakonos::VERSION }
+Code Date: #{ ::Diakonos::LAST_MODIFIED }
+Install Time: #{ File.mtime( File.join( inst[ :lib_dir ], 'diakonos', 'installation.rb' ) ) }
+
+## Paths
+
+Home dir: #{ @diakonos_home }
+
+### Installation
+
+Prefix: #{ inst[ :prefix ] }
+Executable dir: #{ inst[ :bin_dir ] }
+Help dir: #{ inst[ :help_dir ] }
+System config dir: #{ inst[ :conf_dir ] }
+System library dir: #{ inst[ :lib_dir ] }
+
+## Extensions
+
+#{ ext_loaded }
+
+#{ ext_not_loaded }
+ }.strip
+ end
+ end
+
+ end
+end
\ No newline at end of file
diff --git a/lib/diakonos/buffer.rb b/lib/diakonos/buffer.rb
index 034a987..e7d3401 100644
--- a/lib/diakonos/buffer.rb
+++ b/lib/diakonos/buffer.rb
@@ -122,10 +122,12 @@ module Diakonos
def set_language( language )
@settings = @diakonos.settings
@language = language
+ @surround_pairs = @diakonos.surround_pairs[ 'all' ].merge( @diakonos.surround_pairs[ @language ] || Hash.new )
@token_regexps = @diakonos.token_regexps[ 'all' ].merge( @diakonos.token_regexps[ @language ] || Hash.new )
@close_token_regexps = @diakonos.close_token_regexps[ 'all' ].merge( @diakonos.close_token_regexps[ @language ] || Hash.new )
@token_formats = @diakonos.token_formats[ 'all' ].merge( @diakonos.token_formats[ @language ] || Hash.new )
@indenters = @diakonos.indenters[ @language ]
+ @indenters_next_line = @diakonos.indenters_next_line[ @language ]
@unindenters = @diakonos.unindenters[ @language ]
@preventers = @settings[ "lang.#{@language}.indent.preventers" ]
@closers = @diakonos.closers[ @language ] || Hash.new
@@ -191,9 +193,52 @@ module Diakonos
set_modified
end
+ def surround( text, parenthesis )
+ pattern, pair = @surround_pairs.select { |r, p| parenthesis =~ r }.to_a[ 0 ]
+
+ if pair.nil?
+ $diakonos.set_iline "No matching parentheses pair found."
+ nil
+ else
+ pair.map! do |paren|
+ parenthesis.gsub( pattern, paren )
+ end
+ pair[ 0 ] + text.join( "\n" ) + pair[ 1 ]
+ end
+ end
+
+ def join_lines_upward( row = @last_row, strip = DONT_STRIP_LINE )
+ return false if row == 0
+
+ take_snapshot
+
+ line = @lines.delete_at( row )
+ old_line = @lines[ row-1 ]
+
+ new_x_pos = old_line.length
+
+ if strip
+ line.strip!
+
+ # Only prepend a space if the line above isn't empty.
+ if ! old_line.strip.empty?
+ line = ' ' + line
+ new_x_pos += 1
+ end
+ end
+
+ @lines[ row-1 ] << line
+
+ cursor_to( row-1, new_x_pos )
+
+ set_modified
+ end
+
def join_lines( row = @last_row, strip = DONT_STRIP_LINE )
take_snapshot( TYPING )
next_line = @lines.delete_at( row + 1 )
+ return false if next_line.nil?
+
if strip
next_line = ' ' + next_line.strip
end
@@ -503,17 +548,26 @@ module Diakonos
end
def word_under_cursor
- word = nil
+ pos = word_under_cursor_pos
+ return if pos.nil?
+
+ col1 = pos[ 0 ][ 1 ]
+ col2 = pos[ 1 ][ 1 ]
+ @lines[ @last_row ][ col1..col2 ]
+ end
+ def word_under_cursor_pos
@lines[ @last_row ].scan( WORD_REGEXP ) do |match_text|
last_match = Regexp.last_match
- if last_match.begin( 0 ) <= @last_col and @last_col < last_match.end( 0 )
- word = match_text
- break
+ if last_match.begin( 0 ) <= @last_col && @last_col < last_match.end( 0 )
+ return [
+ [ @last_row, last_match.begin( 0 ) ],
+ [ @last_row, last_match.end( 0 ) - 1 ],
+ ]
end
end
- word
+ nil
end
def word_before_cursor
@@ -529,6 +583,49 @@ module Diakonos
word
end
+ # TODO word_before_cursor_pos
+
+ # Returns an array of lines of the current paragraph.
+ def paragraph_under_cursor
+ ( first, _ ), ( last, _ ) = paragraph_under_cursor_pos
+ @lines[ first..last ]
+ end
+
+ # Returns the coordinates of the first and last line of the current
+ # paragraph.
+ def paragraph_under_cursor_pos
+ if @lines[ @last_row ] =~ /^\s*$/
+ return [
+ [ @last_row, 0 ],
+ [ @last_row, @lines[ @last_row ].length - 1 ]
+ ]
+ end
+
+ upper_boundary = 0
+ lower_boundary = @lines.size - 1
+
+ @last_row.downto( 0 ) do |i|
+ line = @lines[ i ]
+ if line =~ /^\s*$/
+ upper_boundary = i + 1
+ break
+ end
+ end
+
+ @last_row.upto( @lines.size - 1 ) do |i|
+ line = @lines[ i ]
+ if line =~ /^\s*$/
+ lower_boundary = i - 1
+ break
+ end
+ end
+
+ [
+ [ upper_boundary, 0 ],
+ [ lower_boundary, @lines[ lower_boundary ].length - 1 ]
+ ]
+ end
+ # TODO paragraph_before_cursor(_pos)?
def words( filter_regexp = nil )
w = @lines.join( ' ' ).scan( WORD_REGEXP )
diff --git a/lib/diakonos/buffer/indentation.rb b/lib/diakonos/buffer/indentation.rb
index 4c072f0..6030b8a 100644
--- a/lib/diakonos/buffer/indentation.rb
+++ b/lib/diakonos/buffer/indentation.rb
@@ -6,8 +6,7 @@ module Diakonos
delta = 0
line = @lines[ row ]
for i in 0...col
- # One comparison for Ruby 1.9, the other for 1.8.
- if line[ i ] == "\t" || line[ i ] == TAB
+ if line[ i ] == "\t"
delta += ( @tab_size - ( (i+delta) % @tab_size ) ) - 1
end
end
@@ -87,6 +86,10 @@ module Diakonos
level = 0
else
prev_line = @lines[ row - i ]
+ second_prev_line = ''
+ if ! ( ( row - i - i ) < 0 )
+ second_prev_line = @lines[ row - i - 1 ]
+ end
level = indentation_level( row - i )
line = @lines[ row ]
@@ -96,14 +99,18 @@ module Diakonos
end
indenter_index = ( prev_line =~ @indenters )
- if indenter_index
+
+ if prev_line =~ @indenters_next_line
+ level += 1
+ elsif indenter_index
level += 1
unindenter_index = (prev_line =~ @unindenters)
if unindenter_index and unindenter_index != indenter_index
level += -1
end
end
- if line =~ @unindenters
+
+ if line =~ @unindenters || second_prev_line =~ @indenters_next_line
level += -1
end
end
@@ -124,4 +131,4 @@ module Diakonos
end
-end
\ No newline at end of file
+end
diff --git a/lib/diakonos/config.rb b/lib/diakonos/config.rb
index c591c16..5b8385b 100644
--- a/lib/diakonos/config.rb
+++ b/lib/diakonos/config.rb
@@ -11,7 +11,7 @@ module Diakonos
EOL_ALT_LAST_CHAR = 3
class Diakonos
- attr_reader :token_regexps, :close_token_regexps, :token_formats, :diakonos_conf, :column_markers
+ attr_reader :token_regexps, :close_token_regexps, :token_formats, :diakonos_conf, :column_markers, :surround_pairs
def fetch_conf( location = "v#{VERSION}" )
require 'open-uri'
@@ -87,10 +87,12 @@ module Diakonos
@token_formats = Hash.new { |h,k| h[ k ] = Hash.new }
@column_markers = Hash.new { |h,k| h[ k ] = Hash.new }
@indenters = Hash.new
+ @indenters_next_line = Hash.new
@unindenters = Hash.new
@filemasks = Hash.new
@bangmasks = Hash.new
@closers = Hash.new
+ @surround_pairs = Hash.new { |h,k| h[ k ] = Hash.new}
@settings = Hash.new
@setting_strings = Hash.new
@@ -168,6 +170,28 @@ module Diakonos
case command
when "include"
parse_configuration_file File.expand_path( arg )
+ when 'load_extension'
+ @extensions.load( arg ).each do |conf_file|
+ parse_configuration_file conf_file
+ end
+ when /^lang\.(.+?)\.surround\.pair$/
+ language = $1
+
+ args = arg.split( /"\s+"/ )
+ args.map! do |s|
+ s.gsub( /(?<!\\)"/, '' ).gsub( /\\"/, '"' )
+ end
+
+ pair_key = args.shift
+
+ if pair_key =~ /^\/.+\/$/
+ pair_key = Regexp.new( pair_key[ 1..-2 ] )
+ else
+ pair_key = Regexp.new( "^#{Regexp.escape(pair_key)}$" )
+ end
+
+ pair_parens = args
+ @surround_pairs[ language ][ pair_key ] = pair_parens
when "key"
if arg
if / / === arg
@@ -221,6 +245,13 @@ module Diakonos
else
@indenters[ $1 ] = Regexp.new arg
end
+ when /^lang\.(.+?)\.indent\.indenters_next_line(\.case_insensitive)?$/
+ case_insensitive = ( $2 != nil )
+ if case_insensitive
+ @indenters_next_line[ $1 ] = Regexp.new( arg, Regexp::IGNORECASE )
+ else
+ @indenters_next_line[ $1 ] = Regexp.new arg
+ end
when /^lang\.(.+?)\.indent\.unindenters(\.case_insensitive)?$/
case_insensitive = ( $2 != nil )
if case_insensitive
diff --git a/lib/diakonos/core-ext/hash.rb b/lib/diakonos/core-ext/hash.rb
index 82cbbd8..5ff51b5 100644
--- a/lib/diakonos/core-ext/hash.rb
+++ b/lib/diakonos/core-ext/hash.rb
@@ -98,11 +98,5 @@ class Hash
end
end
- # Implement Ruby 1.9's Hash#key for Ruby 1.8
- if ! method_defined?( :key )
- def key( *args )
- index( *args )
- end
- end
end
diff --git a/lib/diakonos/core-ext/string.rb b/lib/diakonos/core-ext/string.rb
index 8415399..04ee7d2 100644
--- a/lib/diakonos/core-ext/string.rb
+++ b/lib/diakonos/core-ext/string.rb
@@ -1,4 +1,5 @@
class String
+
def to_b
case downcase
when "true", "t", "1", "yes", "y", "on", "+"
@@ -117,11 +118,5 @@ class String
[ i, match_text ]
end
- # Backport of Ruby 1.9's String#ord into Ruby 1.8
- if ! method_defined?( :ord )
- def ord
- self[ 0 ]
- end
- end
end
diff --git a/lib/diakonos/extension-set.rb b/lib/diakonos/extension-set.rb
new file mode 100644
index 0000000..79cc7fc
--- /dev/null
+++ b/lib/diakonos/extension-set.rb
@@ -0,0 +1,54 @@
+module Diakonos
+
+ class ExtensionSet
+
+ def initialize( root_dir )
+ @extensions = Hash.new
+ @root_dir = File.expand_path( root_dir )
+ end
+
+ def scripts
+ @extensions.values.find_all { |e| e }.map { |e| e.scripts }.flatten
+ end
+
+ def parse_version( s )
+ if s
+ s.split( '.' ).map { |part| part.to_i }.extend( Comparable )
+ end
+ end
+
+ def load( dir )
+ @extensions[ dir ] = false
+
+ confs_to_parse = []
+ ext_dir = File.join( @root_dir, dir )
+ info = YAML.load_file( File.join( ext_dir, 'info.yaml' ) )
+
+ if info[ 'requirements' ] && info[ 'requirements' ][ 'diakonos' ]
+ this_version = parse_version( ::Diakonos::VERSION )
+ min_version = parse_version( info[ 'requirements' ][ 'diakonos' ][ 'minimum' ] )
+ if min_version && this_version >= min_version
+ extension = Extension.new( ext_dir )
+ @extensions[ dir ] = extension
+ confs_to_parse += extension.confs
+ end
+ end
+
+ confs_to_parse
+ end
+
+ def loaded?( ext_dir )
+ @extensions[ ext_dir ]
+ end
+
+ def loaded_extensions
+ @extensions.values.find_all { |e| e }
+ end
+
+ def not_loaded_extensions
+ @extensions.keys.find_all { |e| ! loaded?( e ) }
+ end
+
+ end
+
+end
\ No newline at end of file
diff --git a/lib/diakonos/extension.rb b/lib/diakonos/extension.rb
new file mode 100644
index 0000000..33f592b
--- /dev/null
+++ b/lib/diakonos/extension.rb
@@ -0,0 +1,34 @@
+module Diakonos
+
+ class Extension
+
+ attr_reader :dir, :scripts, :confs
+
+ def initialize( dir )
+ @scripts = []
+ @confs = []
+ @dir = File.basename( dir )
+ @info = YAML.load_file( File.join( dir, 'info.yaml' ) )
+
+ Dir[ File.join( dir, '**', '*.rb' ) ].each do |ext_file|
+ @scripts << ext_file
+ end
+
+ Dir[ File.join( dir, "*.conf" ) ].each do |conf_file|
+ @confs << conf_file
+ end
+ end
+
+ def []( key )
+ @info[ key ]
+ end
+
+ [ 'name', 'description', 'version' ].each do |m|
+ define_method( m ) do
+ @info[ m ]
+ end
+ end
+
+ end
+
+end
\ No newline at end of file
diff --git a/lib/diakonos/functions.rb b/lib/diakonos/functions.rb
index a1df1e5..0e95297 100644
--- a/lib/diakonos/functions.rb
+++ b/lib/diakonos/functions.rb
@@ -1,6 +1,14 @@
module Diakonos
module Functions
+ # Shows the About page, which gives information on Diakonos.
+ def about
+ about_write
+ open_file @about_filename
+ end
+
+ # Deletes characters up to, but not including, a given character.
+ # Also puts the deleted text into the clipboard.
def delete_to( char = nil )
if char.nil?
set_iline "Type character to delete to..."
@@ -17,6 +25,10 @@ module Diakonos
end
end
+ # Deletes characters between, but not including, a given pair of
+ # characters. Also puts the deleted text into the clipboard.
+ # Brace characters are intelligently matched with their opposite-side
+ # counterparts if the left-side brace is given (e.g. '[').
def delete_to_and_from( char = nil )
if char.nil?
set_iline "Type character to delete to and from..."
@@ -33,6 +45,7 @@ module Diakonos
end
end
+ # Evaluates (executes) Ruby code.
def evaluate( code_ = nil )
if code_.nil?
if @current_buffer.changing_selection
@@ -40,9 +53,9 @@ module Diakonos
end
code = get_user_input(
"Ruby code: ",
- @rlh_general,
- selected_text || "",
- ::Diakonos::Functions.public_instance_methods.map { |m| m.to_s }
+ history: @rlh_general,
+ initial_text: selected_text || "",
+ completion_array: ::Diakonos::Functions.public_instance_methods.map { |m| m.to_s }
)
else
code = code_
@@ -65,6 +78,7 @@ module Diakonos
end
end
+ # Starts the interactive help system.
def help( prefill = '' )
if ! File.exist?( @help_dir ) || Dir[ "#{@help_dir}/*" ].size == 0
set_iline 'There are no help files installed.'
@@ -76,9 +90,9 @@ module Diakonos
selected = get_user_input(
"Search terms: ",
- @rlh_help,
- prefill,
- @help_tags
+ history: @rlh_help,
+ initial_text: prefill,
+ completion_array: @help_tags
) { |input|
next if input.length < 3 and input[ 0..0 ] != '/'
@@ -136,9 +150,10 @@ module Diakonos
end
end
+ # Loads Ruby code from file using Kernel#load.
def load_script( name_ = nil )
if name_.nil?
- name = get_user_input( "File to load as script: ", @rlh_files )
+ name = get_user_input( "File to load as script: ", history: @rlh_files )
else
name = name_
end
@@ -198,6 +213,7 @@ module Diakonos
set_iline "Type any chain of keystrokes or key chords, then press Enter..."
end
+ # Quits Diakonos (gracefully).
def quit
@quitting = true
to_all = nil
@@ -229,6 +245,7 @@ module Diakonos
refresh_all
end
+ # Starts or stops macro recording.
def toggle_macro_recording( name = nil )
if @macro_history
stop_recording_macro
@@ -237,10 +254,12 @@ module Diakonos
end
end
+ # Undoes the latest change made to the current_buffer.
def undo( buffer = @current_buffer )
buffer.undo
end
+ # Redoes the latest change undone on the current_buffer.
def unundo( buffer = @current_buffer )
buffer.unundo
end
diff --git a/lib/diakonos/functions/basics.rb b/lib/diakonos/functions/basics.rb
index d0870ac..a2d4755 100644
--- a/lib/diakonos/functions/basics.rb
+++ b/lib/diakonos/functions/basics.rb
@@ -15,10 +15,12 @@ module Diakonos
@current_buffer.delete_selection
end
+ # Calls Buffer#delete on the current_buffer.
def delete
@current_buffer.delete
end
+ # Deletes the current line and adds it to the clipboard.
def delete_line
removed_text = @current_buffer.delete_line
@clipboard.add_clip( [ removed_text, "" ] ) if removed_text
diff --git a/lib/diakonos/functions/buffers.rb b/lib/diakonos/functions/buffers.rb
index ecf7f85..2099f1b 100644
--- a/lib/diakonos/functions/buffers.rb
+++ b/lib/diakonos/functions/buffers.rb
@@ -101,11 +101,18 @@ module Diakonos
end
def list_buffers
+ bullets = ('0'..'9').to_a + ('a'..'z').to_a
with_list_file do |f|
- f.puts @buffers.keys.map { |name| "#{name}\n" }.sort
+ @buffers.keys.sort.each_with_index do |name, index|
+ bullet = bullets[ index ]
+ if bullet
+ bullet << ' '
+ end
+ f.puts "#{bullet}#{name}"
+ end
end
open_list_buffer
- filename = get_user_input( "Switch to buffer: " )
+ filename = get_user_input( "Switch to buffer: ", numbered_completion: true )
buffer = @buffers[ filename ]
if buffer
switch_to buffer
@@ -237,7 +244,12 @@ module Diakonos
open_list_buffer
}
end
- file = get_user_input( "Filename: ", @rlh_files, prefill, &finder_block )
+ file = get_user_input(
+ "Filename: ",
+ history: @rlh_files,
+ initial_text: prefill,
+ &finder_block
+ )
if file
open_file file
@@ -247,7 +259,7 @@ module Diakonos
end
def open_matching_files( regexp = nil, search_root = nil )
- regexp ||= get_user_input( "Regexp: ", @rlh_search )
+ regexp ||= get_user_input( "Regexp: ", history: @rlh_search )
return if regexp.nil?
if @current_buffer.current_line =~ %r{\w*/[/\w.]+}
@@ -255,7 +267,7 @@ module Diakonos
else
prefill = File.expand_path( File.dirname( @current_buffer.name ) ) + "/"
end
- search_root ||= get_user_input( "Search within: ", @rlh_files, prefill )
+ search_root ||= get_user_input( "Search within: ", history: @rlh_files, initial_text: prefill )
return if search_root.nil?
files = `egrep -rl '#{regexp.gsub( /'/, "'\\\\''" )}' #{search_root}/*`.split( /\n/ )
@@ -309,9 +321,9 @@ module Diakonos
def save_file_as
if @current_buffer && @current_buffer.name
path = File.expand_path( File.dirname( @current_buffer.name ) ) + "/"
- file = get_user_input( "Filename: ", @rlh_files, path )
+ file = get_user_input( "Filename: ", history: @rlh_files, initial_text: path )
else
- file = get_user_input( "Filename: ", @rlh_files )
+ file = get_user_input( "Filename: ", history: @rlh_files )
end
if file
old_name = @current_buffer.name
@@ -383,4 +395,4 @@ module Diakonos
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/diakonos/functions/cursor.rb b/lib/diakonos/functions/cursor.rb
index 62326a0..c290d28 100644
--- a/lib/diakonos/functions/cursor.rb
+++ b/lib/diakonos/functions/cursor.rb
@@ -1,7 +1,7 @@
module Diakonos
module Functions
- # Returns true iff the cursor changed positions
+ # @return [true,false] true iff the cursor changed positions
def cursor_down
@current_buffer.cursor_to(
@current_buffer.last_row + 1,
@@ -12,7 +12,7 @@ module Diakonos
)
end
- # Returns true iff the cursor changed positions
+ # @return [true,false] true iff the cursor changed positions
def cursor_left( stopped_typing = Buffer::STOPPED_TYPING )
@current_buffer.cursor_to(
@current_buffer.last_row,
@@ -31,7 +31,7 @@ module Diakonos
)
end
- # Returns true iff the cursor changed positions
+ # @return [true,false] true iff the cursor changed positions
def cursor_up
@current_buffer.cursor_to(
@current_buffer.last_row - 1,
@@ -42,35 +42,40 @@ module Diakonos
)
end
+ # Moves the cursor to the beginning of the current buffer.
def cursor_bof
@current_buffer.cursor_to( 0, 0, Buffer::DO_DISPLAY )
end
+ # Moves the cursor to the beginning of the current line.
def cursor_bol
@current_buffer.cursor_to_bol
end
+ # Moves the cursor to the end of the current line.
def cursor_eol
@current_buffer.cursor_to_eol
end
+ # Moves the cursor to the end of the current buffer.
def cursor_eof
@current_buffer.cursor_to_eof
end
- # Top of view
+ # Moves the cursor to the top of the viewport of the current buffer.
def cursor_tov
@current_buffer.cursor_to_tov
end
- # Bottom of view
+ # Moves the cursor to the bottom of the viewport of the current buffer.
def cursor_bov
@current_buffer.cursor_to_bov
end
+ # Pops the cursor stack of the current buffer.
def cursor_return( dir_str = "backward" )
stack_pointer, stack_size = @current_buffer.cursor_return( direction_of( dir_str, :backward ) )
- set_iline( "Location: #{stack_pointer+1}/#{stack_size}" )
+ set_iline "Location: #{stack_pointer+1}/#{stack_size}"
end
def go_block_outer
@@ -86,6 +91,7 @@ module Diakonos
@current_buffer.go_block_previous
end
+ # Moves the cursor to the next occurrence of the given character.
def go_to_char( char = nil )
char ||= get_char( "Type character to go to..." )
@@ -97,6 +103,7 @@ module Diakonos
end
end
+ # Moves the cursor to the closest previous occurrence of the given character.
def go_to_char_previous( char = nil )
char ||= get_char( "Type character to go to..." )
diff --git a/lib/diakonos/functions/grepping.rb b/lib/diakonos/functions/grepping.rb
index 8dfbd63..4ebcb51 100644
--- a/lib/diakonos/functions/grepping.rb
+++ b/lib/diakonos/functions/grepping.rb
@@ -15,7 +15,13 @@ module Diakonos
def grep_dir( regexp_source = nil, dir = nil )
if dir.nil?
- dir = get_user_input( "Grep directory: ", @rlh_files, @session[ 'dir' ], nil, DONT_COMPLETE, :accept_dirs )
+ dir = get_user_input(
+ "Grep directory: ",
+ history: @rlh_files,
+ initial_text: @session[ 'dir' ],
+ do_complete: DONT_COMPLETE,
+ on_dirs: :accept_dirs
+ )
return if dir.nil?
end
dir = File.expand_path( dir )
@@ -28,8 +34,8 @@ module Diakonos
selected = get_user_input(
"Grep regexp: ",
- @rlh_search,
- regexp_source || selected_text || ""
+ history: @rlh_search,
+ initial_text: regexp_source || selected_text || ""
) { |input|
next if input.length < 2
escaped_input = input.gsub( /'/ ) { "\\047" }
diff --git a/lib/diakonos/functions/search.rb b/lib/diakonos/functions/search.rb
index 3125128..fd3de64 100644
--- a/lib/diakonos/functions/search.rb
+++ b/lib/diakonos/functions/search.rb
@@ -30,7 +30,7 @@ module Diakonos
end
if replacement == ASK_REPLACEMENT
- replacement = get_user_input( "Replace with: ", @rlh_search )
+ replacement = get_user_input( "Replace with: ", history: @rlh_search )
end
if exception_thrown and not quiet
@@ -59,8 +59,8 @@ module Diakonos
regexp_source = get_user_input(
"Search regexp: ",
- @rlh_search,
- ( selected_text or "" )
+ history: @rlh_search,
+ initial_text: selected_text || ""
) { |input|
if input.length > 1
find_ direction, case_sensitive, input, nil, starting_row, starting_col, QUIET
@@ -97,7 +97,11 @@ module Diakonos
if @current_buffer.changing_selection
selected_text = @current_buffer.copy_selection[ 0 ]
end
- search_term = get_user_input( "Search for: ", @rlh_search, ( selected_text or "" ) )
+ search_term = get_user_input(
+ "Search for: ",
+ history: @rlh_search,
+ initial_text: selected_text || ""
+ )
else
search_term = search_term_
end
diff --git a/lib/diakonos/functions/sessions.rb b/lib/diakonos/functions/sessions.rb
index 97e528e..1f85537 100644
--- a/lib/diakonos/functions/sessions.rb
+++ b/lib/diakonos/functions/sessions.rb
@@ -28,7 +28,12 @@ module Diakonos
def load_session( session_id = nil )
if session_id.nil?
- session_id = get_user_input( "Session: ", @rlh_sessions, @session_dir, nil, DO_COMPLETE )
+ session_id = get_user_input(
+ "Session: ",
+ history: @rlh_sessions,
+ initial_text: @session_dir,
+ do_complete: DO_COMPLETE
+ )
end
return if session_id.nil? or session_id.empty?
@@ -59,7 +64,13 @@ module Diakonos
end
def set_session_dir
- path = get_user_input( "Session directory: ", @rlh_files, @session[ 'dir' ], nil, DONT_COMPLETE, :accept_dirs )
+ path = get_user_input(
+ "Session directory: ",
+ history: @rlh_files,
+ initial_text: @session[ 'dir' ],
+ do_complete: DONT_COMPLETE,
+ on_dirs: :accept_dirs
+ )
if path
@session[ 'dir' ] = File.expand_path( path )
save_session
diff --git a/lib/diakonos/functions/shell.rb b/lib/diakonos/functions/shell.rb
index 353180d..68f8940 100644
--- a/lib/diakonos/functions/shell.rb
+++ b/lib/diakonos/functions/shell.rb
@@ -20,7 +20,11 @@ module Diakonos
# Get user input, sub it in
if retval =~ /\$i/
- user_input = get_user_input( "Argument: ", @rlh_shell, @current_buffer.selected_string )
+ user_input = get_user_input(
+ "Argument: ",
+ history: @rlh_shell,
+ initial_text: @current_buffer.selected_string
+ )
retval.gsub!( /\$i/, user_input )
end
@@ -52,7 +56,7 @@ module Diakonos
end
def shell( command_ = nil, result_filename = 'shell-result.txt' )
- command = command_ || get_user_input( "Command: ", @rlh_shell )
+ command = command_ || get_user_input( "Command: ", history: @rlh_shell )
return if command.nil?
@@ -112,7 +116,7 @@ module Diakonos
end
def execute( command_ = nil )
- command = command_ || get_user_input( "Command: ", @rlh_shell )
+ command = command_ || get_user_input( "Command: ", history: @rlh_shell )
return if command.nil?
@@ -134,7 +138,7 @@ module Diakonos
end
def paste_shell_result( command_ = nil )
- command = command_ || get_user_input( "Command: ", @rlh_shell )
+ command = command_ || get_user_input( "Command: ", history: @rlh_shell )
return if command.nil?
@@ -155,7 +159,7 @@ module Diakonos
end
def spawn( command_ = nil )
- command = command_ || get_user_input( "Command: ", @rlh_shell )
+ command = command_ || get_user_input( "Command: ", history: @rlh_shell )
return if command.nil?
diff --git a/lib/diakonos/functions/tags.rb b/lib/diakonos/functions/tags.rb
index 18a8237..3772a02 100644
--- a/lib/diakonos/functions/tags.rb
+++ b/lib/diakonos/functions/tags.rb
@@ -10,7 +10,12 @@ module Diakonos
if @current_buffer.changing_selection
selected_text = @current_buffer.copy_selection[ 0 ]
end
- tag_name = get_user_input( "Tag name: ", @rlh_general, ( selected_text or "" ), @tags.keys )
+ tag_name = get_user_input(
+ "Tag name: ",
+ history: @rlh_general,
+ initial_text: selected_text || "",
+ completion_array: @tags.keys
+ )
else
tag_name = tag_
end
diff --git a/lib/diakonos/functions/text-manipulation.rb b/lib/diakonos/functions/text-manipulation.rb
index ed4bef4..5ccaecc 100644
--- a/lib/diakonos/functions/text-manipulation.rb
+++ b/lib/diakonos/functions/text-manipulation.rb
@@ -13,8 +13,8 @@ module Diakonos
if delimiter.nil?
delimiter = get_user_input(
"Column delimiter (regexp): ",
- @rlh_general,
- @settings[ "lang.#{@current_buffer.original_language}.column_delimiters" ] || ''
+ history: @rlh_general,
+ initial_text: @settings[ "lang.#{@current_buffer.original_language}.column_delimiters" ] || ''
)
end
if delimiter && num_spaces_padding
@@ -75,12 +75,20 @@ module Diakonos
end
end
+ def join_lines_upward
+ @current_buffer.join_lines_upward( @current_buffer.current_row, Buffer::STRIP_LINE )
+ end
+
def join_lines
@current_buffer.join_lines( @current_buffer.current_row, Buffer::STRIP_LINE )
end
def operate_on_string(
- ruby_code = get_user_input( 'Ruby code: ', @rlh_general, 'str.' )
+ ruby_code = get_user_input(
+ 'Ruby code: ',
+ history: @rlh_general,
+ initial_text: 'str.'
+ )
)
if ruby_code
str = @current_buffer.selected_string
@@ -91,7 +99,11 @@ module Diakonos
end
def operate_on_lines(
- ruby_code = get_user_input( 'Ruby code: ', @rlh_general, 'lines.collect { |l| l }' )
+ ruby_code = get_user_input(
+ 'Ruby code: ',
+ history: @rlh_general,
+ initial_text: 'lines.collect { |l| l }'
+ )
)
if ruby_code
lines = @current_buffer.selected_text
@@ -110,7 +122,11 @@ module Diakonos
end
def operate_on_each_line(
- ruby_code = get_user_input( 'Ruby code: ', @rlh_general, 'line.' )
+ ruby_code = get_user_input(
+ 'Ruby code: ',
+ history: @rlh_general,
+ initial_text: 'line.'
+ )
)
if ruby_code
lines = @current_buffer.selected_text
@@ -128,6 +144,48 @@ module Diakonos
end
end
+ def surround_line( envelope = nil )
+ envelope ||= get_user_input( 'Surround with: ' )
+ return if envelope.nil?
+ @current_buffer.select_current_line
+ surround_selection envelope
+ end
+
+ def surround_paragraph( envelope = nil )
+ envelope ||= get_user_input( 'Surround with: ' )
+ return if envelope.nil?
+
+ ( first, _ ), ( last, length ) = @current_buffer.paragraph_under_cursor_pos
+ @current_buffer.set_selection( first, 0, last, length+1 )
+ surround_selection envelope
+ end
+
+ def surround_selection( parenthesis = nil )
+ if ! @current_buffer.selecting?
+ set_iline "Nothing selected."
+ return
+ end
+
+ parenthesis ||= get_user_input( "Parenthesis: " )
+ if parenthesis
+ text = @current_buffer.surround( @current_buffer.selected_text, parenthesis )
+ if text
+ @current_buffer.paste text
+ end
+ end
+ end
+
+ def surround_word( envelope = nil )
+ envelope ||= get_user_input( 'Surround with: ' )
+ return if envelope.nil?
+
+ ( start_row, start_col ), ( end_row, end_col ) = @current_buffer.word_under_cursor_pos
+ if start_row && start_col && end_row && end_col
+ @current_buffer.set_selection( start_row, start_col, end_row, end_col+1 )
+ surround_selection envelope
+ end
+ end
+
def uncomment
@current_buffer.uncomment
end
@@ -137,4 +195,4 @@ module Diakonos
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/diakonos/grep.rb b/lib/diakonos/grep.rb
index 4634aa9..8afbc24 100644
--- a/lib/diakonos/grep.rb
+++ b/lib/diakonos/grep.rb
@@ -61,8 +61,8 @@ module Diakonos
selected = get_user_input(
"Grep regexp: ",
- @rlh_search,
- regexp_source || selected_text || ""
+ history: @rlh_search,
+ initial_text: regexp_source || selected_text || ""
) { |input|
next if input.length < 2
actually_grep input, *buffers
diff --git a/lib/diakonos/interaction.rb b/lib/diakonos/interaction.rb
index ae26721..27d45cd 100644
--- a/lib/diakonos/interaction.rb
+++ b/lib/diakonos/interaction.rb
@@ -37,11 +37,16 @@ module Diakonos
class Diakonos
# completion_array is the array of strings that tab completion can use
- def get_user_input( prompt, history = @rlh_general, initial_text = "", completion_array = nil, do_complete = DONT_COMPLETE, on_dirs = :go_into_dirs, &block )
+ # @param options :initial_text, :completion_array, :history, :do_complete, :on_dirs
+ def get_user_input( prompt, options = {}, &block )
+ options[ :history ] ||= @rlh_general
+ options[ :initial_text ] ||= ""
+ options[ :do_complete ] ||= DONT_COMPLETE
+ options[ :on_dirs ] ||= :go_into_dirs
if @playing_macro
retval = @macro_input_history.shift
else
- retval = Readline.new( self, @win_interaction, prompt, initial_text, completion_array, history, do_complete, on_dirs, &block ).readline
+ retval = Readline.new( self, @win_interaction, prompt, options, &block ).readline
if @macro_history
@macro_input_history.push retval
end
diff --git a/lib/diakonos/list.rb b/lib/diakonos/list.rb
index 519991c..3d51f82 100644
--- a/lib/diakonos/list.rb
+++ b/lib/diakonos/list.rb
@@ -1,6 +1,7 @@
module Diakonos
class Diakonos
+ attr_reader :list_buffer
def open_list_buffer
@list_buffer = open_file( @list_filename )
@@ -55,4 +56,4 @@ module Diakonos
end
-end
\ No newline at end of file
+end
diff --git a/lib/diakonos/readline.rb b/lib/diakonos/readline.rb
index abf85aa..5f946d6 100644
--- a/lib/diakonos/readline.rb
+++ b/lib/diakonos/readline.rb
@@ -4,22 +4,26 @@ module Diakonos
# completion_array is the array of strings that tab completion can use
# The block returns true if a refresh is needed?
- def initialize( diakonos, window, prompt, initial_text = "", completion_array = nil, history = [], do_complete = Diakonos::DONT_COMPLETE, on_dirs = :go_into_dirs, &block )
+ # @param options :initial_text, :completion_array, :history, :do_complete, :on_dirs
+ def initialize( diakonos, window, prompt, options = {}, &block )
@diakonos = diakonos
@window = window
@prompt = prompt
pos = redraw_prompt
@window.setpos( 0, pos )
- @initial_text = initial_text || ''
- @completion_array = completion_array
+ @initial_text = options[ :initial_text ] || ''
+ @completion_array = options[ :completion_array ]
@list_filename = @diakonos.list_filename
- @history = history
- @history << initial_text
+ @history = options[ :history ] || []
+ @history << @initial_text
@history_index = @history.length - 1
- @do_complete = do_complete
- @on_dirs = on_dirs
+ @do_complete = options[ :do_complete ] || ::Diakonos::DONT_COMPLETE
+ @on_dirs = options[ :on_dirs ] || :go_into_dirs
+
+ # TODO think of better name
+ @numbered_completion = options [ :numbered_completion ]
@block = block
end
@@ -35,6 +39,13 @@ module Diakonos
end
end
+ def set_input( input = '' )
+ if @numbered_completion && input =~ /^\w /
+ input = input[ 3..-1 ]
+ end
+ @input = input
+ end
+
# Returns nil on cancel.
def readline
@input = @initial_text.dup
@@ -59,7 +70,7 @@ module Diakonos
when Curses::KEY_DC
if @input_cursor < @input.length
@window.delch
- @input = @input[ 0...@input_cursor ] + @input[ (@input_cursor + 1)..-1 ]
+ set_input( @input[ 0...@input_cursor ] + @input[ (@input_cursor + 1)..-1 ] )
call_block
end
when BACKSPACE, CTRL_H
@@ -71,7 +82,7 @@ module Diakonos
# Curses::KEY_DC
if @input_cursor < @input.length
@window.delch
- @input = @input[ 0...@input_cursor ] + @input[ (@input_cursor + 1)..-1 ]
+ set_input( @input[ 0...@input_cursor ] + @input[ (@input_cursor + 1)..-1 ] )
call_block
end
end
@@ -107,14 +118,14 @@ module Diakonos
@diakonos.page_down
line = @diakonos.select_list_item
if line
- @input = line
+ set_input line
cursor_write_input
end
when Curses::KEY_PPAGE
@diakonos.page_up
line = @diakonos.select_list_item
if line
- @input = line
+ set_input line
cursor_write_input
end
when Curses::KEY_UP
@@ -122,7 +133,7 @@ module Diakonos
if @diakonos.list_item_selected?
@diakonos.previous_list_item
end
- @input = @diakonos.select_list_item
+ set_input @diakonos.select_list_item
elsif @history_index > 0
@history[ @history_index ] = @input
@history_index -= 1
@@ -134,7 +145,7 @@ module Diakonos
if @diakonos.list_item_selected?
@diakonos.next_list_item
end
- @input = @diakonos.select_list_item
+ set_input @diakonos.select_list_item
elsif @history_index < @history.length - 1
@history[ @history_index ] = @input
@history_index += 1
@@ -161,16 +172,33 @@ module Diakonos
cursor_write_input
else
if c > 31 && c < 255 && c != BACKSPACE
- if @input_cursor == @input.length
- @input << c
- @window.addch c
+ if @numbered_completion
+ if(
+ @diakonos.showing_list? &&
+ ( (48..57).include?( c ) || (97..122).include?( c ) )
+ )
+ line = @diakonos.list_buffer.to_a.select { |l|
+ l =~ /^#{c.chr} /
+ }[ 0 ]
+
+ if line
+ set_input line
+ cursor_write_input
+ break
+ end
+ end
else
- @input = @input[ 0...@input_cursor ] + c.chr + @input[ @input_cursor..-1 ]
- @window.setpos( @window.cury, @window.curx + 1 )
- redraw_input
+ if @input_cursor == @input.length
+ @input << c
+ @window.addch c
+ else
+ @input = @input[ 0...@input_cursor ] + c.chr + @input[ @input_cursor..-1 ]
+ @window.setpos( @window.cury, @window.curx + 1 )
+ redraw_input
+ end
+ @input_cursor += 1
+ call_block
end
- @input_cursor += 1
- call_block
else
@diakonos.log "Other input: #{c}"
end
@@ -244,8 +272,6 @@ module Diakonos
f.print match
if FileTest.directory?( match )
f.print '/'
- else
- @diakonos.log "'#{match}' is not a directory"
end
f.puts
@@ -281,4 +307,4 @@ module Diakonos
end
-end
\ No newline at end of file
+end
diff --git a/lib/diakonos/version.rb b/lib/diakonos/version.rb
index 9571c4d..b87f92b 100644
--- a/lib/diakonos/version.rb
+++ b/lib/diakonos/version.rb
@@ -1,4 +1,4 @@
module Diakonos
- VERSION = '0.8.10'
- LAST_MODIFIED = 'June 17, 2009'
+ VERSION = '0.8.11'
+ LAST_MODIFIED = 'June 30, 2009'
end
\ No newline at end of file
diff --git a/osx.conf b/osx.conf
deleted file mode 100644
index aeb8244..0000000
--- a/osx.conf
+++ /dev/null
@@ -1,62 +0,0 @@
-# Additional configuration for OSX
-# --------------------------------
-
-# Linux Alt --> OSX Option
-
-key keycode195 keycode165 columnize
-# key keycode226 keycode136 keycode171
-key keycode195 keycode167 close_code
-key keycode226 keycode136 keycode130 shell "diff -U 5 -w -b $k $s", "clipboard.diff"
-# Option-E doesn't do anything
-key keycode198 keycode146 find "down", CASE_SENSITIVE
-key keycode194 keycode169 grep
-# key keycode203 keycode153
-# Option-I doesn't do anything
-key keycode226 keycode136 keycode134 joinLines
-key keycode203 keycode154 printKeychain
-# key keycode194 keycode172
-key keycode194 keycode181 toggleMacroRecording
-# Option-N doesn't do anything
-key keycode195 keycode184 open_matching_files
-key keycode207 keycode128 scrollUp
-# key keycode197 keycode147
-key keycode194 keycode174 searchAndReplace CASE_SENSITIVE
-# key keycode195 keycode159
-key keycode226 keycode128 keycode160 goToTag
-# Option-U doesn't do anything
-# key keycode226 keycode136 keycode154
-key keycode226 keycode136 keycode145 wrap_paragraph
-# key keycode226 keycode137 keycode136
-# Option-Y doesn't do anything
-# key keycode206 keycode169
-
-
-# Linux Alt-Shift --> OSX Option-Shift
-
-# key keycode195 keycode133
-# key keycode196 keycode177
-key keycode195 keycode135 toggleSessionSetting 'context.visible', DO_REDRAW
-# key keycode195 keycode142
-# key keycode194 keycode180
-# key keycode195 keycode143
-key keycode203 keycode157 grep_buffers
-# key keycode195 keycode147
-key keycode203 keycode134 unindent
-# key keycode195 keycode148
-key keycode239 keycode163 keycode191 print_mapped_function
-key keycode195 keycode146 toggleSessionSetting 'view.line_numbers', DO_REDRAW
-key keycode195 keycode130 keycode196 keycode177 selection_mode_block
-key keycode195 keycode130 keycode203 keycode156 selection_mode_normal
-key keycode203 keycode156 scrollDown
-# key keycode195 keycode152
-# key keycode226 keycode136 keycode143
-# key keycode197 keycode146
-# key keycode226 keycode128 keycode176
-key keycode195 keycode141 saveFileAs
-key keycode203 keycode135 setBufferType
-key keycode194 keycode168 removeSelection
-# key keycode226 keycode151 keycode138
-key keycode226 keycode128 keycode158 toggleSessionSetting 'view.wrap.visual', DO_REDRAW
-# key keycode203 keycode155
-# key keycode195 keycode129
-# key keycode194 keycode184
diff --git a/scripts/git-branch.rb b/scripts/git-branch.rb
deleted file mode 100644
index f550d68..0000000
--- a/scripts/git-branch.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-git_proc = Proc.new do |buffer|
- if buffer and buffer.name
- dir = File.dirname( File.expand_path( buffer.name ) )
- else
- dir = '.'
- end
-
- if File.exist? dir
- branch = Dir.chdir( dir ){ `git symbolic-ref HEAD 2>/dev/null`[ /[^\/\n]+$/ ] }
- $diakonos.set_status_variable(
- '@git_branch',
- branch ? " git:#{branch} " : nil
- )
- end
-end
-
-$diakonos.register_proc( git_proc, :after_open )
-$diakonos.register_proc( git_proc, :after_buffer_switch )
diff --git a/spec/buffer.rb b/spec/buffer.rb
index 1aac062..085903b 100644
--- a/spec/buffer.rb
+++ b/spec/buffer.rb
@@ -1,10 +1,19 @@
require 'spec/preparation'
+def check_word_at( row, col, expected_word )
+ @b.cursor_to row, col
+ @b.word_under_cursor.should.equal expected_word
+end
+
+def check_paragraph_at( row, col, expected_paragraph )
+ @b.cursor_to row, col
+ @b.paragraph_under_cursor.should.equal expected_paragraph
+end
+
describe 'A Diakonos::Buffer' do
before do
@b = Diakonos::Buffer.new( $diakonos, SAMPLE_FILE, SAMPLE_FILE )
- @b.cursor_to( 0, 0 )
end
it 'can provide selected text' do
@@ -128,6 +137,28 @@ describe 'A Diakonos::Buffer' do
indent_rows
@b.save_copy TEMP_FILE
File.read( TEMP_FILE ).should.equal File.read( SAMPLE_FILE )
+
+ # -------
+
+ @b = Diakonos::Buffer.new( $diakonos, SAMPLE_FILE_C, SAMPLE_FILE_C )
+
+ indent_rows 0, 14
+ @b.save_copy TEMP_FILE_C
+ File.read( TEMP_FILE_C ).should.equal File.read( SAMPLE_FILE_C )
+
+ @b.cursor_to( 3, 0 )
+ @b.insert_string " "
+ @b.cursor_to( 10, 0 )
+ @b.insert_string " "
+ @b.cursor_to( 12, 0 )
+ @b.insert_string " "
+
+ @b.save_copy TEMP_FILE_C
+ File.read( TEMP_FILE_C ).should.not.equal File.read( SAMPLE_FILE_C )
+
+ indent_rows 0, 14
+ @b.save_copy TEMP_FILE_C
+ File.read( TEMP_FILE_C ).should.equal File.read( SAMPLE_FILE_C )
end
it 'can paste an Array of Strings' do
@@ -144,4 +175,64 @@ describe 'A Diakonos::Buffer' do
@b.to_a.should.equal original_lines[ 1..-1 ]
end
+ it 'knows the word under the cursor' do
+ check_word_at 0, 16, 'ruby'
+ check_word_at 2, 0, nil
+ check_word_at 2, 2, 'This'
+ check_word_at 2, 3, 'This'
+ check_word_at 2, 4, 'This'
+ check_word_at 2, 5, 'This'
+ check_word_at 2, 6, nil
+ check_word_at 2, 45, 'tests'
+ check_word_at 2, 46, nil
+ check_word_at 2, 47, nil
+ check_word_at 3, 0, nil
+ check_word_at 5, 14, nil
+ check_word_at 5, 15, 'x'
+ check_word_at 5, 16, nil
+ check_word_at 14, 4, 'y'
+ check_word_at 14, 5, nil
+ check_word_at 14, 6, 'inspect'
+ check_word_at 21, 0, nil
+ check_word_at 22, 8, nil
+ check_word_at 22, 9, nil
+ check_word_at 26, 39, 'EOF'
+ check_word_at 26, 40, nil
+ end
+
+ it 'knows the paragraph under the cursor' do
+ check_paragraph_at 0, 0, [
+ '#!/usr/bin/env ruby',
+ ]
+ check_paragraph_at 2, 0, [
+ '# This is only a sample file used in the tests.',
+ ]
+ check_paragraph_at 4, 0, [
+ 'class Sample',
+ ' attr_reader :x, :y',
+ ]
+ check_paragraph_at 7, 0, [
+ ' def initialize',
+ ' @x = 1',
+ ' @y = 2',
+ ' end',
+ ]
+ check_paragraph_at 14, 7, [
+ ' def inspection',
+ ' x.inspect',
+ ' y.inspect',
+ ' end',
+ 'end',
+ ]
+ check_paragraph_at 22, 7, [
+ '{',
+ ' :just => :a,',
+ ' :test => :hash,',
+ '}',
+ ]
+ check_paragraph_at 26, 12, [
+ '# Comment at end, with no newline at EOF',
+ ]
+ end
+
end
\ No newline at end of file
diff --git a/spec/functions/clipboard.rb b/spec/functions/clipboard.rb
index 0a4ae14..e413ae5 100644
--- a/spec/functions/clipboard.rb
+++ b/spec/functions/clipboard.rb
@@ -40,7 +40,7 @@ describe 'A Diakonos user can' do
]
lines = @b.to_a
- lines.size.should.equal 23
+ lines.size.should.equal 24
lines[ 0..2 ].should.equal [
'',
'class Sample',
@@ -55,7 +55,7 @@ describe 'A Diakonos user can' do
@d.paste
lines = @b.to_a
- lines.size.should.equal 29
+ lines.size.should.equal 30
lines[ 0..8 ].should.equal [
'#!/usr/bin/env ruby',
'',
diff --git a/spec/functions/cursor.rb b/spec/functions/cursor.rb
index 053232c..2c2fc51 100644
--- a/spec/functions/cursor.rb
+++ b/spec/functions/cursor.rb
@@ -37,7 +37,7 @@ describe 'A Diakonos user can' do
it 'move the cursor to the end of a file' do
@d.cursor_eof
- cursor_should_be_at 25,0
+ cursor_should_be_at 26,40
end
it 'move the cursor to the beginning of a file' do
@@ -64,7 +64,7 @@ describe 'A Diakonos user can' do
it 'move the cursor to the closest previous occurrence of a character' do
@d.cursor_eof
- cursor_should_be_at 25,0
+ cursor_should_be_at 26,40
@d.go_to_char_previous '.'
cursor_should_be_at 19,1
@d.go_to_char_previous 'e'
diff --git a/spec/functions/selection.rb b/spec/functions/selection.rb
index 8ee798d..56ebd83 100644
--- a/spec/functions/selection.rb
+++ b/spec/functions/selection.rb
@@ -42,8 +42,8 @@ describe 'A Diakonos user can' do
s = @b.selection_mark
s.start_row.should.equal 0
s.start_col.should.equal 0
- s.end_row.should.equal 25
- s.end_col.should.equal 0
+ s.end_row.should.equal 26
+ s.end_col.should.equal 40
end
it 'delete the selection' do
diff --git a/spec/functions/text-manipulation.rb b/spec/functions/text-manipulation.rb
index 17ef4e7..a23cb66 100644
--- a/spec/functions/text-manipulation.rb
+++ b/spec/functions/text-manipulation.rb
@@ -116,7 +116,7 @@ describe 'A Diakonos user can' do
@b.cursor_to 22,2
@d.delete_to_and_from '{'
lines = @b.to_a
- lines.size.should.equal 23
+ lines.size.should.equal 24
lines[ 21..22 ].should.equal [
'{}',
'',
@@ -156,6 +156,7 @@ describe 'A Diakonos user can' do
':test => :hash,',
'}',
'',
+ '# Comment at end, with no newline at EOF',
]
@d.set_buffer_type 'ruby'
@@ -188,6 +189,7 @@ describe 'A Diakonos user can' do
' :test => :hash,',
'}',
'',
+ '# Comment at end, with no newline at EOF',
]
end
@@ -206,4 +208,36 @@ describe 'A Diakonos user can' do
]
end
+ it 'surround selections with parentheses' do
+ @b.set_selection 4, 6, 4, 12
+ @d.surround_selection '('
+ @b[ 4 ].should.equal 'class ( Sample )'
+ @d.undo
+
+ @b.set_selection 4, 0, 4, 12
+ @d.surround_selection '('
+ @b[ 4 ].should.equal '( class Sample )'
+ @d.undo
+
+ @b.set_selection 4, 0, 5, 20
+ @d.surround_selection '('
+ @b[ 4..5 ].should.equal [
+ '( class Sample',
+ ' attr_reader :x, :y )'
+ ]
+ @d.undo
+
+ @b.set_type 'html'
+
+ @b.set_selection 7, 2, 7, 5
+ @d.surround_selection '<!--'
+ @b[ 7 ].should.equal ' <!-- def --> initialize'
+ @d.undo
+
+ @b.set_selection 7, 2, 7, 5
+ @d.surround_selection '<span>'
+ @b[ 7 ].should.equal ' <span>def</span> initialize'
+ @d.undo
+ end
+
end
diff --git a/spec/preparation.rb b/spec/preparation.rb
index 9012a5c..c22c579 100644
--- a/spec/preparation.rb
+++ b/spec/preparation.rb
@@ -13,12 +13,18 @@ end
if ! Object.const_defined? 'SAMPLE_FILE'
SAMPLE_FILE = File.join( TEST_DIR, '/sample-file.rb' )
end
+if ! Object.const_defined? 'SAMPLE_FILE_C'
+ SAMPLE_FILE_C = File.join( TEST_DIR, '/sample-file.c' )
+end
if ! Object.const_defined? 'BRACKET_FILE'
BRACKET_FILE = File.join( TEST_DIR, '/bracket-file.rb' )
end
if ! Object.const_defined? 'TEMP_FILE'
TEMP_FILE = File.join( TEST_DIR, '/temp-file.rb' )
end
+if ! Object.const_defined? 'TEMP_FILE_C'
+ TEMP_FILE_C = File.join( TEST_DIR, '/temp-file.c' )
+end
def cursor_should_be_at( row, col )
@b.current_row.should.equal row
diff --git a/spec/test-files/sample-file.c b/spec/test-files/sample-file.c
new file mode 100644
index 0000000..2810af9
--- /dev/null
+++ b/spec/test-files/sample-file.c
@@ -0,0 +1,16 @@
+#include <stdio.h>
+
+int main() {
+ printf( "Hello World!\n" );
+
+ if( condition ) {
+ f();
+ }
+
+ if( condition )
+ g();
+
+ h();
+
+ return 0;
+}
diff --git a/spec/test-files/sample-file.rb b/spec/test-files/sample-file.rb
index c8b6eba..aa38fd5 100644
--- a/spec/test-files/sample-file.rb
+++ b/spec/test-files/sample-file.rb
@@ -23,3 +23,5 @@ s.inspection
:just => :a,
:test => :hash,
}
+
+# Comment at end, with no newline at EOF
\ No newline at end of file
diff --git a/spec/test-files/temp-file.c b/spec/test-files/temp-file.c
new file mode 100644
index 0000000..2810af9
--- /dev/null
+++ b/spec/test-files/temp-file.c
@@ -0,0 +1,16 @@
+#include <stdio.h>
+
+int main() {
+ printf( "Hello World!\n" );
+
+ if( condition ) {
+ f();
+ }
+
+ if( condition )
+ g();
+
+ h();
+
+ return 0;
+}