Просто добавьте мои $ 0.02 в коллекцию решений:
У меня была такая же потребность еще в 2011 году и была создана MultiDictionary
с педантично полной реализацией всех интерфейсов .NET. Это включает перечисления, которые возвращают стандарт KeyValuePair
и поддерживают свойство IDictionary
, предоставляя набор фактических значений (вместо ICollection
).
Таким образом, он вписывается аккуратно с остальными классов коллекции .NET. Я также определил интерфейс IMultiDictionary
для доступа к операциям, которые относятся к этому типу словаря:
public interface IMultiDictionary :
IDictionary>,
IDictionary,
ICollection>,
IEnumerable>,
IEnumerable {
/// Adds a value into the dictionary
/// Key the value will be stored under
/// Value that will be stored under the key
void Add(TKey key, TValue value);
/// Determines the number of values stored under a key
/// Key whose values will be counted
/// The number of values stored under the specified key
int CountValues(TKey key);
///
/// Removes the item with the specified key and value from the dictionary
///
/// Key of the item that will be removed
/// Value of the item that will be removed
/// True if the item was found and removed
bool Remove(TKey key, TValue value);
/// Removes all items of a key from the dictionary
/// Key of the items that will be removed
/// The number of items that have been removed
int RemoveKey(TKey key);
}
Его можно скомпилировать на любом из .NET 2.0 вверх и пока я развернул его на Xbox 360, Windows Phone 7, Linux и Unity 3D.
Код лицензируется в соответствии с Common Public License (коротко: все идет, но исправления ошибок в библиотеке код должен быть опубликован) и можно найти в моем репозитории Subversion .
На основе Вашей обратной связи к моему первому ответу, как насчет этого:
(defun my-isearch-word-at-point ()
(interactive)
(call-interactively 'isearch-forward-regexp))
(defun my-isearch-yank-word-hook ()
(when (equal this-command 'my-isearch-word-at-point)
(let ((string (concat "\\<"
(buffer-substring-no-properties
(progn (skip-syntax-backward "w_") (point))
(progn (skip-syntax-forward "w_") (point)))
"\\>")))
(if (and isearch-case-fold-search
(eq 'not-yanks search-upper-case))
(setq string (downcase string)))
(setq isearch-string string
isearch-message
(concat isearch-message
(mapconcat 'isearch-text-char-description
string ""))
isearch-yank-flag t)
(isearch-search-and-update))))
(add-hook 'isearch-mode-hook 'my-isearch-yank-word-hook)
Я не попробовал его, но существует некоторый код здесь назван Grep-O-Matic.
С этим необходимо быть в состоянии сделать C -* в то время как в isearch режиме.
(define-key isearch-mode-map [?\C-*] 'kmk-isearch-yank-thing) (defun kmk-isearch-yank-thing () "Pull next thing from buffer into search string." (interactive) (let ((string (regexp-quote (thing-at-point 'word)))) (setq isearch-string (concat isearch-string "\\") isearch-message (concat isearch-message (mapconcat 'isearch-text-char-description string "")) ;; Don't move cursor in reverse search. isearch-yank-flag t)) (setq isearch-regexp t isearch-word nil isearch-success t isearch-adjusted t) (isearch-search-and-update))
ответ Скоттфрейзера мне подходит, за исключением слов, оканчивающихся на '_' (или, возможно, других символов, не являющихся словами?). Я обнаружил, что код для режима светового символа использовал другое регулярное выражение для границы слова в зависимости от версии emacs, и это исправило его для меня. Вот измененный код:
(defconst my-isearch-rx-start
(if (< emacs-major-version 22)
"\\<"
"\\_<")
"Start-of-symbol regular expression marker.")
(defconst my-isearch-rx-end
(if (< emacs-major-version 22)
"\\>"
"\\_>")
"End-of-symbol regular expression marker.")
(defun my-isearch-word-at-point ()
(interactive)
(call-interactively 'isearch-forward-regexp))
(defun my-isearch-yank-word-hook ()
(when (equal this-command 'my-isearch-word-at-point)
(let ((string (concat my-isearch-rx-start
(buffer-substring-no-properties
(progn (skip-syntax-backward "w_") (point))
(progn (skip-syntax-forward "w_") (point)))
my-isearch-rx-end)))
(if (and isearch-case-fold-search
(eq 'not-yanks search-upper-case))
(setq string (downcase string)))
(setq isearch-string string
isearch-message
(concat isearch-message
(mapconcat 'isearch-text-char-description
string ""))
isearch-yank-flag t)
(isearch-search-and-update))))
(add-hook 'isearch-mode-hook 'my-isearch-yank-word-hook)
;Here is my version: Emulates Visual Studio/Windows key bindings ; C-F3 - Start searching the word at the point ; F3 searches forward and Shift F3 goes reverse (setq my-search-wrap nil) (defun my-search-func (dir) (interactive) (let* ((text (car search-ring)) newpoint) (when my-search-wrap (goto-char (if (= dir 1) (point-min) (point-max))) (setq my-search-wrap nil)) (setq newpoint (search-forward text nil t dir)) (if newpoint (set-mark (if (= dir 1) (- newpoint (length text)) (+ newpoint (length text)))) (message "Search Failed: %s" text) (ding) (setq my-search-wrap text)))) (defun my-search-fwd () (interactive) (my-search-func 1)) (defun my-search-bwd () (interactive) (my-search-func -1)) (defun yank-thing-into-search () (interactive) (let ((text (if mark-active (buffer-substring-no-properties (region-beginning)(region-end)) (or (current-word) "")))) (when (> (length text) 0) (isearch-update-ring text) (setq my-search-wrap nil) (my-search-fwd)))) (global-set-key (kbd "") 'my-search-fwd) ; Visual Studio like search keys (global-set-key (kbd "") 'my-search-bwd) (global-set-key (kbd "") 'yank-thing-into-search)
Как насчет встроенных команд Mb Cs Cw (начало слова, поиск, поиск слова)