textbringer-recentf 1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2b12d05d8ed3520a2514ce6931439343ca9f900b6a0f75efa7c1ff5e28aa0dae
4
+ data.tar.gz: 1d358ff5003e6693601e58be895eb2e2bf3f28e6b2146751aee0bd731331c599
5
+ SHA512:
6
+ metadata.gz: 899e72623c4ed4ba72528b1f8fd192561a72a6844ff24481f399baa5d4bc5bff51efd0b2ee1ab67f30da1e39206a848d21d59d9c956cbdafc6f5d8ea2b6f6cdf
7
+ data.tar.gz: 7574cad9c78232faf010753dc990feb42482982084a561691b94edc5ab5d7d149d5cc2c9dbc4b3dfb9b5a6b6aa3f369d7f62f158e385e325df4890cc54879f9b
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/
10
+ *.gem
11
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "textbringer-minibuffer-extension"
6
+
7
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Akihiro Kurotani
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # textbringer-recentf
2
+
3
+ Emacs-like recent file history plugin for [Textbringer](https://github.com/shugo/textbringer).
4
+
5
+ ## Dependencies
6
+
7
+ - [textbringer](https://github.com/shugo/textbringer) >= 1.4
8
+ - [textbringer-minibuffer-extension](https://github.com/kurod1492/textbringer-minibuffer-extension) >= 0.1.0
9
+
10
+ ## Installation
11
+
12
+ ### Via git clone
13
+
14
+ Clone this repository and its dependency to your Textbringer plugins directory:
15
+
16
+ ```bash
17
+ # Install dependency
18
+ git clone https://github.com/kurod1492/textbringer-minibuffer-extension.git ~/.textbringer/plugins/textbringer-minibuffer-extension
19
+
20
+ # Install this plugin
21
+ git clone https://github.com/kurod1492/textbringer-recentf.git ~/.textbringer/plugins/textbringer-recentf
22
+ ```
23
+
24
+ ### Via rake install
25
+
26
+ After checking out the repo, run `bundle install` to install dependencies.
27
+
28
+ To install this gem onto your local machine, run `bundle exec rake install`.
29
+
30
+ Note: You also need to install the dependency [textbringer-minibuffer-extension](https://github.com/kurod1492/textbringer-minibuffer-extension).
31
+
32
+ ## Configuration
33
+
34
+ Add the following to your `~/.textbringer.rb`:
35
+
36
+ ```ruby
37
+ # Key binding (optional)
38
+ GLOBAL_MAP.define_key("\C-x\C-r", :recentf)
39
+
40
+ # Maximum number of files to remember (default: 100)
41
+ CONFIG[:recentf_max_items] = 100
42
+
43
+ # History file path (default: ~/.textbringer/recentf)
44
+ CONFIG[:recentf_file] = "~/.textbringer/recentf"
45
+
46
+ # Patterns to exclude from history
47
+ CONFIG[:recentf_exclude_patterns] = [
48
+ %r{^/tmp/},
49
+ %r{COMMIT_EDITMSG$}
50
+ ]
51
+ ```
52
+
53
+ ## Usage
54
+
55
+ | Command | Description |
56
+ |---------|-------------|
57
+ | `M-x recentf` | Open a file from recent history |
58
+ | `M-x recentf_cleanup` | Remove non-existent files from history |
59
+
60
+ ## License
61
+
62
+ MIT
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb", "test/**/test_*.rb"]
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Textbringer
4
+ module Recentf
5
+ VERSION = "1"
6
+ end
7
+ end
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "recentf/version"
4
+
5
+ module Textbringer
6
+ CONFIG[:recentf_max_items] = 100
7
+ CONFIG[:recentf_file] = File.expand_path("~/.textbringer/recentf")
8
+ CONFIG[:recentf_exclude_patterns] = [
9
+ %r{^/tmp/},
10
+ %r{COMMIT_EDITMSG$}
11
+ ]
12
+
13
+ module Recentf
14
+ @last_added = nil
15
+
16
+ class << self
17
+ attr_accessor :last_added
18
+
19
+ def file_path
20
+ File.expand_path(CONFIG[:recentf_file])
21
+ end
22
+
23
+ def max_items
24
+ CONFIG[:recentf_max_items]
25
+ end
26
+
27
+ def exclude_patterns
28
+ CONFIG[:recentf_exclude_patterns]
29
+ end
30
+
31
+ def load
32
+ return [] unless File.exist?(file_path)
33
+ File.readlines(file_path, chomp: true)
34
+ end
35
+
36
+ def save(list)
37
+ dir = File.dirname(file_path)
38
+ FileUtils.mkdir_p(dir) unless File.directory?(dir)
39
+ File.write(file_path, list.take(max_items).join("\n") + "\n")
40
+ end
41
+
42
+ def add(path)
43
+ return if path.nil? || path.empty?
44
+ path = File.expand_path(path)
45
+ return if exclude_patterns.any? { |pat| pat.match?(path) }
46
+ return if path == last_added
47
+
48
+ list = load
49
+ list.delete(path)
50
+ list.unshift(path)
51
+ save(list)
52
+ self.last_added = path
53
+ end
54
+
55
+ def cleanup
56
+ list = load.select { |f| File.exist?(f) }
57
+ save(list)
58
+ list.size
59
+ end
60
+ end
61
+ end
62
+
63
+ define_command(:recentf, doc: "Open a file from recent file history.") do
64
+ list = Recentf.load
65
+ if list.empty?
66
+ raise EditorError, "No recent files"
67
+ end
68
+
69
+ completion_proc = ->(s) {
70
+ list.select { |f| f.include?(s) }
71
+ }
72
+ file = read_from_minibuffer("Recent file: ",
73
+ completion_proc: completion_proc,
74
+ history: list)
75
+ MinibufferHistory.add(:file, file) if defined?(MinibufferHistory)
76
+ find_file(file)
77
+ end
78
+
79
+ define_command(:recentf_cleanup,
80
+ doc: "Remove non-existent files from recent file history.") do
81
+ count = Recentf.cleanup
82
+ message("Cleaned up. #{count} files remaining.")
83
+ end
84
+
85
+ # Track buffer switches to files
86
+ # Cannot use this_command check because recursive_edit in minibuffer
87
+ # clears this_command before post_command_hook runs
88
+ add_hook(:post_command_hook) do
89
+ file = Buffer.current&.file_name
90
+ if file && !file.empty?
91
+ Recentf.add(file)
92
+ end
93
+ end
94
+
95
+ # Record files specified on command line (txtb filename)
96
+ # foreground runs after command_loop starts, when files are already opened
97
+ foreground do
98
+ ARGV.each do |arg|
99
+ path = File.expand_path(arg)
100
+ Recentf.add(path) if File.exist?(path)
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "textbringer/recentf"
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "textbringer/recentf/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "textbringer-recentf"
9
+ spec.version = Textbringer::Recentf::VERSION
10
+ spec.authors = ["Akihiro Kurotani"]
11
+ spec.email = ["kurod1492@gmail.com"]
12
+
13
+ spec.summary = "Recent file history plugin for Textbringer."
14
+ spec.description = "Provides Emacs-like recent file history functionality for Textbringer."
15
+ spec.homepage = "https://github.com/kurod1492/textbringer-recentf"
16
+ spec.license = "MIT"
17
+ spec.metadata = { "rubygems_mfa_required" => "true" }
18
+
19
+ spec.required_ruby_version = ">= 3.2"
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
22
+ f.match(%r{^(test|spec|features)/})
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_runtime_dependency "textbringer", ">= 1.4"
29
+ spec.add_runtime_dependency "textbringer-minibuffer-extension", ">= 1"
30
+
31
+ spec.add_development_dependency "bundler"
32
+ spec.add_development_dependency "rake", ">= 12.0"
33
+ spec.add_development_dependency "test-unit"
34
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: textbringer-recentf
3
+ version: !ruby/object:Gem::Version
4
+ version: '1'
5
+ platform: ruby
6
+ authors:
7
+ - Akihiro Kurotani
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: textbringer
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '1.4'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '1.4'
26
+ - !ruby/object:Gem::Dependency
27
+ name: textbringer-minibuffer-extension
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '1'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '1'
40
+ - !ruby/object:Gem::Dependency
41
+ name: bundler
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rake
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '12.0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '12.0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: test-unit
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ description: Provides Emacs-like recent file history functionality for Textbringer.
83
+ email:
84
+ - kurod1492@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".gitignore"
90
+ - Gemfile
91
+ - LICENSE.txt
92
+ - README.md
93
+ - Rakefile
94
+ - lib/textbringer/recentf.rb
95
+ - lib/textbringer/recentf/version.rb
96
+ - lib/textbringer_plugin.rb
97
+ - textbringer-recentf.gemspec
98
+ homepage: https://github.com/kurod1492/textbringer-recentf
99
+ licenses:
100
+ - MIT
101
+ metadata:
102
+ rubygems_mfa_required: 'true'
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '3.2'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubygems_version: 4.0.7
118
+ specification_version: 4
119
+ summary: Recent file history plugin for Textbringer.
120
+ test_files: []