Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1152 lines
46 KiB

4 years ago
  1. ;;; helm-buffers.el --- helm support for buffers. -*- lexical-binding: t -*-
  2. ;; Copyright (C) 2012 ~ 2019 Thierry Volpiatto <thierry.volpiatto@gmail.com>
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;; This program is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ;; GNU General Public License for more details.
  11. ;; You should have received a copy of the GNU General Public License
  12. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ;;; Code:
  14. (require 'cl-lib)
  15. (require 'helm)
  16. (require 'helm-types)
  17. (require 'helm-utils)
  18. (require 'helm-grep)
  19. (require 'helm-regexp)
  20. (require 'helm-help)
  21. (require 'helm-occur)
  22. (declare-function ido-make-buffer-list "ido" (default))
  23. (declare-function ido-add-virtual-buffers-to-list "ido")
  24. (declare-function helm-comp-read "helm-mode")
  25. (declare-function helm-browse-project "helm-files")
  26. (defgroup helm-buffers nil
  27. "Buffers related Applications and libraries for Helm."
  28. :group 'helm)
  29. (defcustom helm-boring-buffer-regexp-list
  30. '("\\` " "\\`\\*helm" "\\`\\*Echo Area" "\\`\\*Minibuf")
  31. "The regexp list that match boring buffers.
  32. Buffer candidates matching these regular expression will be
  33. filtered from the list of candidates if the
  34. `helm-skip-boring-buffers' candidate transformer is used."
  35. :type '(repeat (choice regexp))
  36. :group 'helm-buffers)
  37. (defcustom helm-white-buffer-regexp-list nil
  38. "The regexp list of not boring buffers.
  39. These buffers will be displayed even if they match one of
  40. `helm-boring-buffer-regexp-list'."
  41. :type '(repeat (choice regexp))
  42. :group 'helm-buffers)
  43. (defcustom helm-buffers-favorite-modes '(lisp-interaction-mode
  44. emacs-lisp-mode
  45. text-mode
  46. org-mode)
  47. "List of preferred mode to open new buffers with."
  48. :type '(repeat (choice function))
  49. :group 'helm-buffers)
  50. (defcustom helm-buffer-max-length 20
  51. "Max length of buffer names before truncate.
  52. When disabled (nil) use the longest buffer-name length found."
  53. :group 'helm-buffers
  54. :type '(choice (const :tag "Disabled" nil)
  55. (integer :tag "Length before truncate")))
  56. (defcustom helm-buffer-details-flag t
  57. "Always show details in buffer list when non--nil."
  58. :group 'helm-buffers
  59. :type 'boolean)
  60. (defcustom helm-buffers-fuzzy-matching nil
  61. "Fuzzy matching buffer names when non--nil.
  62. Only buffer names are fuzzy matched when this is enabled,
  63. `major-mode' matching is not affected by this."
  64. :group 'helm-buffers
  65. :type 'boolean)
  66. (defcustom helm-buffer-skip-remote-checking nil
  67. "Ignore checking for `file-exists-p' on remote files."
  68. :group 'helm-buffers
  69. :type 'boolean)
  70. (defcustom helm-buffers-truncate-lines t
  71. "Truncate lines in `helm-buffers-list' when non--nil."
  72. :group 'helm-buffers
  73. :type 'boolean)
  74. (defcustom helm-buffers-left-margin-width helm-left-margin-width
  75. "`left-margin-width' value for `helm-mini' and `helm-buffers-list'."
  76. :group 'helm-buffers
  77. :type 'integer)
  78. (defcustom helm-mini-default-sources '(helm-source-buffers-list
  79. helm-source-recentf
  80. helm-source-buffer-not-found)
  81. "Default sources list used in `helm-mini'.
  82. When adding a source here it is up to you to ensure the library of
  83. this source is accessible and properly loaded."
  84. :group 'helm-buffers
  85. :type '(repeat (choice symbol)))
  86. (defcustom helm-buffers-end-truncated-string "..."
  87. "The string to display at end of truncated buffer names."
  88. :type 'string
  89. :group 'helm-buffers)
  90. (defcustom helm-buffers-column-separator " "
  91. "Separator for columns in buffer listing."
  92. :type 'string
  93. :group 'helm-buffers)
  94. (defcustom helm-buffer--pretty-names '((dired-mode . "Dired")
  95. (lisp-interaction-mode . "Lisp Inter"))
  96. "An alist specifying pretty names for modes.
  97. Most of the time buffer's `mode-name' is a string so no need to add it
  98. here as there is no need to compute it, but sometimes it may be a
  99. mode-line specification which may be costly to compute, in this case
  100. add here the pretty name as a string to avoid this costly computation.
  101. Also if some pretty names are too long you can add your own
  102. abbreviation here."
  103. :type '(alist :key-type symbol :value-type string)
  104. :group 'helm-buffers)
  105. (defcustom helm-buffers-maybe-switch-to-tab nil
  106. "Switch to buffer in its tab when non nil.
  107. This have no effect when `tab-bar-mode' is not available."
  108. :group 'helm-buffers
  109. :type 'boolean)
  110. ;;; Faces
  111. ;;
  112. ;;
  113. (defgroup helm-buffers-faces nil
  114. "Customize the appearance of helm-buffers."
  115. :prefix "helm-"
  116. :group 'helm-buffers
  117. :group 'helm-faces)
  118. (defface helm-buffer-saved-out
  119. '((t (:foreground "red" :background "black")))
  120. "Face used for buffer files modified outside of emacs."
  121. :group 'helm-buffers-faces)
  122. (defface helm-buffer-not-saved
  123. '((t (:foreground "Indianred2")))
  124. "Face used for buffer files not already saved on disk."
  125. :group 'helm-buffers-faces)
  126. (defface helm-buffer-modified
  127. '((t :inherit font-lock-comment-face))
  128. "Face used for modified buffers."
  129. :group 'helm-buffers-faces)
  130. (defface helm-buffer-size
  131. '((((background dark)) :foreground "RosyBrown")
  132. (((background light)) :foreground "SlateGray"))
  133. "Face used for buffer size."
  134. :group 'helm-buffers-faces)
  135. (defface helm-buffer-process
  136. '((t (:foreground "Sienna3")))
  137. "Face used for process status in buffer."
  138. :group 'helm-buffers-faces)
  139. (defface helm-buffer-directory
  140. '((t (:foreground "DarkRed" :background "LightGray")))
  141. "Face used for directories in `helm-buffers-list'."
  142. :group 'helm-buffers-faces)
  143. (defface helm-buffer-file
  144. '((t :inherit font-lock-builtin-face))
  145. "Face for buffer file names in `helm-buffers-list'."
  146. :group 'helm-buffers-faces)
  147. (defface helm-buffer-archive
  148. '((t (:foreground "Gold")))
  149. "Face for archive file names in `helm-buffers-list'."
  150. :group 'helm-buffers-faces)
  151. (defface helm-non-file-buffer
  152. '((t (:inherit italic)))
  153. "Face used for non-file buffers in `helm-buffers-list'."
  154. :group 'helm-buffers-faces)
  155. (defvar helm-buffers-tick-counter nil
  156. "Allows recording local changes to a non-file buffer.
  157. Typical usage of this var is for modes that want to see if
  158. their buffers have changed since last visit.
  159. Such programs may want to record tick counter after visiting their
  160. buffers like this:
  161. (setq helm-buffers-tick-counter (buffer-modified-tick))
  162. Note that this variable is buffer-local.")
  163. (make-variable-buffer-local 'helm-buffers-tick-counter)
  164. ;;; Buffers keymap
  165. ;;
  166. (defvar helm-buffer-map
  167. (let ((map (make-sparse-keymap)))
  168. (set-keymap-parent map helm-map)
  169. ;; No need to have separate command for grep and zgrep
  170. ;; as we don't use recursivity for buffers.
  171. ;; So use zgrep for both as it is capable to handle non--compressed files.
  172. (define-key map (kbd "M-g s") 'helm-buffer-run-zgrep)
  173. (define-key map (kbd "C-s") 'helm-buffers-run-occur)
  174. (define-key map (kbd "C-x C-d") 'helm-buffers-run-browse-project)
  175. (define-key map (kbd "C-c o") 'helm-buffer-switch-other-window)
  176. (define-key map (kbd "C-c C-o") 'helm-buffer-switch-other-frame)
  177. (define-key map (kbd "C-c =") 'helm-buffer-run-ediff)
  178. (define-key map (kbd "M-=") 'helm-buffer-run-ediff-merge)
  179. (define-key map (kbd "C-=") 'helm-buffer-diff-persistent)
  180. (define-key map (kbd "M-G") 'helm-buffer-revert-persistent)
  181. (define-key map (kbd "C-c d") 'helm-buffer-run-kill-persistent)
  182. (define-key map (kbd "M-D") 'helm-buffer-run-kill-buffers)
  183. (define-key map (kbd "C-x C-s") 'helm-buffer-save-persistent)
  184. (define-key map (kbd "C-x s") 'helm-buffer-run-save-some-buffers)
  185. (define-key map (kbd "C-M-%") 'helm-buffer-run-query-replace-regexp)
  186. (define-key map (kbd "M-%") 'helm-buffer-run-query-replace)
  187. (define-key map (kbd "M-R") 'helm-buffer-run-rename-buffer)
  188. (define-key map (kbd "M-m") 'helm-toggle-all-marks)
  189. (define-key map (kbd "M-a") 'helm-mark-all)
  190. (define-key map (kbd "C-]") 'helm-toggle-buffers-details)
  191. (define-key map (kbd "C-c a") 'helm-buffers-toggle-show-hidden-buffers)
  192. (define-key map (kbd "C-M-SPC") 'helm-buffers-mark-similar-buffers)
  193. (when (fboundp 'tab-bar-mode)
  194. (define-key map (kbd "C-c C-t") 'helm-buffers-switch-to-buffer-new-tab))
  195. map)
  196. "Keymap for buffer sources in helm.")
  197. (defvar helm-buffers-ido-virtual-map
  198. (let ((map (make-sparse-keymap)))
  199. (set-keymap-parent map helm-map)
  200. (define-key map (kbd "C-c o") 'helm-ff-run-switch-other-window)
  201. (define-key map (kbd "C-c C-o") 'helm-ff-run-switch-other-frame)
  202. (define-key map (kbd "M-g s") 'helm-ff-run-grep)
  203. (define-key map (kbd "M-g z") 'helm-ff-run-zgrep)
  204. (define-key map (kbd "M-D") 'helm-ff-run-delete-file)
  205. (define-key map (kbd "C-c C-x") 'helm-ff-run-open-file-externally)
  206. map))
  207. (defvar helm-buffer-max-len-mode nil)
  208. (defvar helm-buffers-in-project-p nil)
  209. (defvar helm-source-buffers-list nil)
  210. (defun helm-buffers-list--init ()
  211. (require 'dired)
  212. ;; Issue #51 Create the list before `helm-buffer' creation.
  213. ;; We were using a global cache in the past and 'candidates was
  214. ;; bound to this cache, this was a problem when using more than one
  215. ;; source with a different 'buffer-list fn as the same cache was
  216. ;; reused in each source (issue #1907), now 'candidates attr is set
  217. ;; directly so that each list of candidates is local to source.
  218. (helm-attrset 'candidates (funcall (helm-attr 'buffer-list)))
  219. (let ((result (cl-loop with allbufs = (memq 'helm-shadow-boring-buffers
  220. (helm-attr
  221. 'filtered-candidate-transformer
  222. helm-source-buffers-list))
  223. for b in (if allbufs
  224. (helm-attr 'candidates)
  225. (helm-skip-boring-buffers
  226. (helm-attr 'candidates)
  227. helm-source-buffers-list))
  228. maximize (length b) into len-buf
  229. maximize (length (helm-buffer--format-mode-name b))
  230. into len-mode
  231. finally return (cons len-buf len-mode))))
  232. (unless (default-value 'helm-buffer-max-length)
  233. (helm-set-local-variable 'helm-buffer-max-length (car result)))
  234. (unless (default-value 'helm-buffer-max-len-mode)
  235. (helm-set-local-variable 'helm-buffer-max-len-mode (cdr result)))))
  236. (defclass helm-source-buffers (helm-source-sync helm-type-buffer)
  237. ((buffer-list
  238. :initarg :buffer-list
  239. :initform #'helm-buffer-list
  240. :custom function
  241. :documentation
  242. " A function with no arguments to create buffer list.")
  243. (init :initform 'helm-buffers-list--init)
  244. (multimatch :initform nil)
  245. (match :initform 'helm-buffers-match-function)
  246. (persistent-action :initform 'helm-buffers-list-persistent-action)
  247. (keymap :initform helm-buffer-map)
  248. (migemo :initform 'nomultimatch)
  249. (volatile :initform t)
  250. (nohighlight :initform t)
  251. (resume :initform (lambda () (setq helm-buffers-in-project-p nil)))
  252. (help-message :initform 'helm-buffer-help-message)))
  253. (cl-defun helm-buffers-create-new-buffer-1 (candidate &optional (display-func 'switch-to-buffer))
  254. (let ((mjm (or (and helm-current-prefix-arg
  255. (intern-soft (helm-comp-read
  256. "Major-mode: "
  257. helm-buffers-favorite-modes)))
  258. (cl-loop for (r . m) in auto-mode-alist
  259. when (string-match r candidate)
  260. return m)))
  261. (buffer (get-buffer-create candidate)))
  262. (if mjm
  263. (with-current-buffer buffer (funcall mjm))
  264. (set-buffer-major-mode buffer))
  265. (funcall display-func buffer)))
  266. (defun helm-buffers-create-new-buffer (candidate)
  267. (helm-buffers-create-new-buffer-1 candidate))
  268. (defun helm-buffers-create-new-buffer-ow (candidate)
  269. (helm-buffers-create-new-buffer-1 candidate 'switch-to-buffer-other-window))
  270. (defun helm-buffers-not-found-run-switch-ow ()
  271. "Run create new buffer other window action from keymap."
  272. (interactive)
  273. (with-helm-alive-p
  274. (helm-exit-and-execute-action 'helm-buffers-create-new-buffer-ow)))
  275. (put 'helm-buffers-not-found-run-switch-ow 'helm-only t)
  276. (defun helm-buffers-create-new-buffer-of (candidate)
  277. (helm-buffers-create-new-buffer-1 candidate 'switch-to-buffer-other-frame))
  278. (defun helm-buffers-not-found-run-switch-of ()
  279. "Run create new buffer other frame action from keymap."
  280. (interactive)
  281. (with-helm-alive-p
  282. (helm-exit-and-execute-action 'helm-buffers-create-new-buffer-of)))
  283. (put 'helm-buffers-not-found-run-switch-of 'helm-only t)
  284. (defvar helm-buffer-not-found-map
  285. (let ((map (make-sparse-keymap)))
  286. (set-keymap-parent map helm-map)
  287. (define-key map (kbd "C-c o") 'helm-buffers-not-found-run-switch-ow)
  288. (define-key map (kbd "C-c C-o") 'helm-buffers-not-found-run-switch-of)
  289. map)
  290. "Keymap for `helm-source-buffer-not-found' source.")
  291. (defvar helm-source-buffer-not-found
  292. (helm-build-dummy-source
  293. "Create buffer"
  294. :action (helm-make-actions
  295. "Create buffer (C-u choose mode)"
  296. #'helm-buffers-create-new-buffer
  297. "Create buffer other window (C-u choose mode)"
  298. #'helm-buffers-create-new-buffer-ow
  299. "Create buffer other frame (C-u choose mode)"
  300. #'helm-buffers-create-new-buffer-of)
  301. :keymap helm-buffer-not-found-map))
  302. (defvar ido-temp-list)
  303. (defvar ido-ignored-list)
  304. (defvar ido-process-ignore-lists)
  305. (defvar ido-use-virtual-buffers)
  306. (defvar ido-virtual-buffers)
  307. (defvar helm-source-ido-virtual-buffers
  308. (helm-build-sync-source "Ido virtual buffers"
  309. :candidates (lambda ()
  310. (let (ido-temp-list
  311. ido-ignored-list
  312. (ido-process-ignore-lists t))
  313. (when ido-use-virtual-buffers
  314. (ido-add-virtual-buffers-to-list)
  315. ido-virtual-buffers)))
  316. :fuzzy-match helm-buffers-fuzzy-matching
  317. :keymap helm-buffers-ido-virtual-map
  318. :help-message 'helm-buffers-ido-virtual-help-message
  319. :action '(("Find file" . helm-find-many-files)
  320. ("Find file other window" . find-file-other-window)
  321. ("Find file other frame" . find-file-other-frame)
  322. ("Find file as root" . helm-find-file-as-root)
  323. ("Grep File(s) `C-u recurse'" . helm-find-files-grep)
  324. ("Zgrep File(s) `C-u Recurse'" . helm-ff-zgrep)
  325. ("View file" . view-file)
  326. ("Delete file(s)" . helm-delete-marked-files)
  327. ("Open file externally (C-u to choose)"
  328. . helm-open-file-externally))))
  329. (defvar ido-use-virtual-buffers)
  330. (defvar ido-ignore-buffers)
  331. (defun helm-buffer-list ()
  332. "Return the current list of buffers.
  333. Currently visible buffers are put at the end of the list.
  334. See `ido-make-buffer-list' for more infos."
  335. (require 'ido)
  336. (let ((ido-process-ignore-lists t)
  337. ido-ignored-list
  338. ido-ignore-buffers
  339. ido-use-virtual-buffers)
  340. (ido-make-buffer-list nil)))
  341. (defun helm-buffer-size (buffer)
  342. "Return size of BUFFER."
  343. (with-current-buffer buffer
  344. (save-restriction
  345. (widen)
  346. (helm-file-human-size
  347. (- (position-bytes (point-max))
  348. (position-bytes (point-min)))))))
  349. (defun helm-buffer--show-details (buf-name prefix help-echo
  350. size mode dir face1 face2
  351. proc details type)
  352. (append
  353. (list
  354. (concat prefix
  355. (propertize buf-name 'face face1
  356. 'help-echo help-echo
  357. 'type type)))
  358. (and details
  359. (list size mode
  360. (propertize
  361. (if proc
  362. (format "(%s %s in `%s')"
  363. (process-name proc)
  364. (process-status proc) dir)
  365. (format "(in `%s')" dir))
  366. 'face face2)))))
  367. (defun helm-buffer--format-mode-name (buf)
  368. "Prevent using `format-mode-line' as much as possible."
  369. (with-current-buffer buf
  370. (helm-acond ((assq major-mode helm-buffer--pretty-names)
  371. (cdr it))
  372. ((stringp mode-name) mode-name)
  373. (t (format-mode-line mode-name)))))
  374. (defun helm-buffer--details (buffer &optional details)
  375. (require 'dired)
  376. (let* ((mode (helm-buffer--format-mode-name buffer))
  377. (buf (get-buffer buffer))
  378. (size (propertize (helm-buffer-size buf)
  379. 'face 'helm-buffer-size))
  380. (proc (get-buffer-process buf))
  381. (dir (with-current-buffer buffer
  382. (helm-aif default-directory (abbreviate-file-name it))))
  383. (file-name (helm-aif (buffer-file-name buf) (abbreviate-file-name it)))
  384. (name (buffer-name buf))
  385. (name-prefix (when (and dir (file-remote-p dir))
  386. (propertize "@ " 'face 'helm-ff-prefix)))
  387. (archive-p (and (fboundp 'tramp-archive-file-name-p)
  388. (tramp-archive-file-name-p dir))))
  389. (when name-prefix
  390. ;; Remote tramp buffer names may be hexified, make them more readable.
  391. (setq dir (helm-url-unhex-string dir)
  392. name (helm-url-unhex-string name)))
  393. ;; Handle tramp archive buffers specially.
  394. (if archive-p
  395. (helm-buffer--show-details
  396. name name-prefix file-name size mode dir
  397. 'helm-buffer-archive 'helm-buffer-process nil details 'filebuf)
  398. ;; No fancy things on remote buffers.
  399. (if (and name-prefix helm-buffer-skip-remote-checking)
  400. (helm-buffer--show-details
  401. name name-prefix file-name size mode dir
  402. 'helm-buffer-file 'helm-buffer-process nil details 'filebuf)
  403. (cond
  404. (;; A dired buffer.
  405. (rassoc buf dired-buffers)
  406. (helm-buffer--show-details
  407. name name-prefix dir size mode dir
  408. 'helm-buffer-directory 'helm-buffer-process nil details 'dired))
  409. ;; A buffer file modified somewhere outside of emacs.=>red
  410. ((and file-name
  411. (file-exists-p file-name)
  412. (not (verify-visited-file-modtime buf)))
  413. (helm-buffer--show-details
  414. name name-prefix file-name size mode dir
  415. 'helm-buffer-saved-out 'helm-buffer-process nil details 'modout))
  416. ;; A new buffer file not already saved on disk (or a deleted file) .=>indianred2
  417. ((and file-name (not (file-exists-p file-name)))
  418. (helm-buffer--show-details
  419. name name-prefix file-name size mode dir
  420. 'helm-buffer-not-saved 'helm-buffer-process nil details 'notsaved))
  421. ;; A buffer file modified and not saved on disk.=>orange
  422. ((and file-name (buffer-modified-p buf))
  423. (helm-buffer--show-details
  424. name name-prefix file-name size mode dir
  425. 'helm-buffer-modified 'helm-buffer-process nil details 'mod))
  426. ;; A buffer file not modified and saved on disk.=>green
  427. (file-name
  428. (helm-buffer--show-details
  429. name name-prefix file-name size mode dir
  430. 'helm-buffer-file 'helm-buffer-process nil details 'filebuf))
  431. ;; A non-file, modified buffer
  432. ((with-current-buffer name
  433. (and helm-buffers-tick-counter
  434. (/= helm-buffers-tick-counter (buffer-modified-tick))))
  435. (helm-buffer--show-details
  436. name (and proc name-prefix) dir size mode dir
  437. 'helm-buffer-modified 'helm-buffer-process proc details 'nofile-mod))
  438. ;; Any non--file buffer.=>italic
  439. (t
  440. (helm-buffer--show-details
  441. name (and proc name-prefix) dir size mode dir
  442. 'helm-non-file-buffer 'helm-buffer-process proc details 'nofile)))))))
  443. (defun helm-highlight-buffers (buffers _source)
  444. "Transformer function to highlight BUFFERS list.
  445. Should be called after others transformers i.e (boring buffers)."
  446. (cl-loop for i in buffers
  447. for (name size mode meta) = (if helm-buffer-details-flag
  448. (helm-buffer--details i 'details)
  449. (helm-buffer--details i))
  450. for truncbuf = (if (> (string-width name) helm-buffer-max-length)
  451. (helm-substring-by-width
  452. name helm-buffer-max-length
  453. helm-buffers-end-truncated-string)
  454. (concat name
  455. (make-string
  456. (- (+ helm-buffer-max-length
  457. (length
  458. helm-buffers-end-truncated-string))
  459. (string-width name))
  460. ? )))
  461. for len = (length mode)
  462. when (> len helm-buffer-max-len-mode)
  463. do (setq helm-buffer-max-len-mode len)
  464. for fmode = (concat (make-string
  465. (- (max helm-buffer-max-len-mode len) len) ? )
  466. mode)
  467. ;; The max length of a number should be 1023.9X where X is the
  468. ;; units, this is 7 characters.
  469. for formatted-size = (and size (format "%7s" size))
  470. collect (let ((helm-pattern (helm-buffers--pattern-sans-filters
  471. (and helm-buffers-fuzzy-matching ""))))
  472. (cons (if helm-buffer-details-flag
  473. (concat
  474. (funcall helm-fuzzy-matching-highlight-fn
  475. truncbuf)
  476. helm-buffers-column-separator
  477. formatted-size
  478. helm-buffers-column-separator
  479. fmode
  480. helm-buffers-column-separator
  481. meta)
  482. (funcall helm-fuzzy-matching-highlight-fn name))
  483. (get-buffer i)))))
  484. (defun helm-buffer--get-preselection (buffer)
  485. (let ((bufname (buffer-name buffer)))
  486. (when (and bufname
  487. (file-remote-p (with-current-buffer bufname
  488. default-directory)))
  489. (setq bufname (concat "@ " (helm-url-unhex-string bufname))))
  490. (concat "^"
  491. (if (and (null helm-buffer-details-flag)
  492. (numberp helm-buffer-max-length)
  493. (> (string-width bufname)
  494. helm-buffer-max-length))
  495. (regexp-quote
  496. (helm-substring-by-width
  497. bufname helm-buffer-max-length
  498. helm-buffers-end-truncated-string))
  499. (concat (regexp-quote bufname)
  500. (if helm-buffer-details-flag
  501. "$" "[[:blank:]]+"))))))
  502. (defun helm-toggle-buffers-details ()
  503. (interactive)
  504. (with-helm-alive-p
  505. (let* ((buf (helm-get-selection))
  506. (preselect (helm-buffer--get-preselection buf)))
  507. (setq helm-buffer-details-flag (not helm-buffer-details-flag))
  508. (helm-update (lambda ()
  509. (helm-awhile (re-search-forward preselect nil t)
  510. (helm-mark-current-line)
  511. (when (equal buf (helm-get-selection))
  512. (cl-return t))))))))
  513. (put 'helm-toggle-buffers-details 'helm-only t)
  514. (defun helm-buffers--pattern-sans-filters (&optional separator)
  515. (cl-loop for p in (helm-mm-split-pattern helm-pattern)
  516. unless (member (substring p 0 1) '("*" "/" "@" "!"))
  517. collect p into lst
  518. finally return (mapconcat 'identity lst (or separator " "))))
  519. (defun helm-buffers-sort-transformer (candidates source)
  520. (if (string= helm-pattern "")
  521. candidates
  522. (if helm-buffers-fuzzy-matching
  523. (let ((helm-pattern (helm-buffers--pattern-sans-filters)))
  524. (funcall helm-fuzzy-sort-fn candidates source))
  525. (sort candidates
  526. (lambda (s1 s2)
  527. (< (string-width s1) (string-width s2)))))))
  528. (defun helm-buffers-mark-similar-buffers-1 (&optional type)
  529. (with-helm-window
  530. (let* ((src (helm-get-current-source))
  531. (type (or type
  532. (get-text-property
  533. 0 'type (helm-get-selection nil 'withprop src)))))
  534. (save-excursion
  535. (goto-char (helm-get-previous-header-pos))
  536. (helm-next-line)
  537. (let* ((next-head (helm-get-next-header-pos))
  538. (end (and next-head
  539. (save-excursion
  540. (goto-char next-head)
  541. (forward-line -1)
  542. (point))))
  543. (maxpoint (or end (point-max))))
  544. (while (< (point) maxpoint)
  545. (helm-mark-current-line)
  546. (let ((cand (helm-get-selection nil 'withprop src)))
  547. (when (and (not (helm-this-visible-mark))
  548. (eq (get-text-property 0 'type cand) type))
  549. (helm-make-visible-mark)))
  550. (forward-line 1) (end-of-line))))
  551. (helm-mark-current-line)
  552. (helm-display-mode-line src t)
  553. (when helm-marked-candidates
  554. (message "%s candidates marked" (length helm-marked-candidates))))))
  555. (defun helm-buffers-mark-similar-buffers ()
  556. "Mark All buffers that have same property `type' than current.
  557. i.e same color."
  558. (interactive)
  559. (with-helm-alive-p
  560. (let ((marked (helm-marked-candidates)))
  561. (if (and (>= (length marked) 1)
  562. (with-helm-window helm-visible-mark-overlays))
  563. (helm-unmark-all)
  564. (helm-buffers-mark-similar-buffers-1)))))
  565. (put 'helm-buffers-mark-similar-buffers 'helm-only t)
  566. ;;; match functions
  567. ;;
  568. (defun helm-buffer--match-mjm (pattern mjm)
  569. (when (string-match "\\`\\*" pattern)
  570. (cl-loop with patterns = (split-string (substring pattern 1) ",")
  571. for pat in patterns
  572. if (string-match "\\`!" pat)
  573. collect (string-match (substring pat 1) mjm) into neg
  574. else collect (string-match pat mjm) into pos
  575. finally return
  576. (let ((neg-test (cl-loop for i in neg thereis (numberp i)))
  577. (pos-test (cl-loop for i in pos thereis (numberp i))))
  578. (or
  579. (and neg (not pos) (not neg-test))
  580. (and pos pos-test)
  581. (and neg neg-test (not neg-test)))))))
  582. (defvar helm-buffer--memo-hash (make-hash-table :test 'equal))
  583. (defun helm-buffer--memo-pattern (pattern)
  584. (or (gethash pattern helm-buffer--memo-hash)
  585. (puthash pattern (helm--mapconcat-pattern pattern)
  586. helm-buffer--memo-hash)))
  587. (defun helm-buffer--match-pattern (pattern candidate &optional nofuzzy)
  588. (let ((bfn (if (and helm-buffers-fuzzy-matching
  589. (not nofuzzy)
  590. (not helm-migemo-mode)
  591. (not (string-match "\\`\\^" pattern)))
  592. #'helm-buffer--memo-pattern
  593. #'identity))
  594. (mfn (if helm-migemo-mode
  595. #'helm-mm-migemo-string-match #'string-match)))
  596. (if (string-match "\\`!" pattern)
  597. (not (funcall mfn (funcall bfn (substring pattern 1))
  598. candidate))
  599. (funcall mfn (funcall bfn pattern) candidate))))
  600. (defun helm-buffers--match-from-mjm (candidate)
  601. (let* ((cand (replace-regexp-in-string "^\\s-\\{1\\}" "" candidate))
  602. (buf (get-buffer cand))
  603. (regexp (cl-loop with pattern = helm-pattern
  604. for p in (helm-mm-split-pattern pattern)
  605. when (string-match "\\`\\*" p)
  606. return p)))
  607. (if regexp
  608. (when buf
  609. (with-current-buffer buf
  610. (let ((mjm (symbol-name major-mode)))
  611. (helm-buffer--match-mjm regexp mjm))))
  612. t)))
  613. (defun helm-buffers--match-from-pat (candidate)
  614. (let* ((regexp-list (cl-loop with pattern = helm-pattern
  615. for p in (helm-mm-split-pattern pattern)
  616. unless (string-match
  617. "\\`\\(\\*\\|/\\|@\\)" p)
  618. collect p))
  619. (nofuzzy (cdr regexp-list)))
  620. (if regexp-list
  621. (cl-loop for re in regexp-list
  622. always (helm-buffer--match-pattern re candidate nofuzzy))
  623. t)))
  624. (defun helm-buffers--match-from-inside (candidate)
  625. (let* ((cand (replace-regexp-in-string "^\\s-\\{1\\}" "" candidate))
  626. (buf (get-buffer cand))
  627. (regexp (cl-loop with pattern = helm-pattern
  628. for p in (helm-mm-split-pattern pattern)
  629. when (string-match "\\`@\\(.*\\)" p)
  630. return (match-string 1 p))))
  631. (if (and buf regexp)
  632. (with-current-buffer buf
  633. (save-excursion
  634. (goto-char (point-min))
  635. (if helm-migemo-mode
  636. (helm-mm-migemo-forward regexp nil t)
  637. (re-search-forward regexp nil t))))
  638. t)))
  639. (defun helm-buffers--match-from-directory (candidate)
  640. (let* ((cand (replace-regexp-in-string "^\\s-\\{1\\}" "" candidate))
  641. (buf (get-buffer cand))
  642. (buf-fname (or (buffer-file-name buf)
  643. (car-safe (rassoc buf dired-buffers))))
  644. (regexps (cl-loop with pattern = helm-pattern
  645. for p in (helm-mm-split-pattern pattern)
  646. when (string-match "\\`/" p)
  647. collect p)))
  648. (if regexps
  649. (cl-loop for re in regexps
  650. thereis
  651. (and buf-fname
  652. (string-match
  653. (substring re 1) (helm-basedir buf-fname))))
  654. t)))
  655. (defun helm-buffers-match-function (candidate)
  656. "Default function to match buffers."
  657. (and (helm-buffers--match-from-pat candidate)
  658. (helm-buffers--match-from-mjm candidate)
  659. (helm-buffers--match-from-inside candidate)
  660. (helm-buffers--match-from-directory candidate)))
  661. (defun helm-buffer-query-replace-1 (&optional regexp-flag buffers)
  662. "Query replace in marked buffers.
  663. If REGEXP-FLAG is given use `query-replace-regexp'."
  664. (let ((prompt (if regexp-flag "Query replace regexp" "Query replace"))
  665. (bufs (or buffers (helm-marked-candidates)))
  666. (helm--reading-passwd-or-string t))
  667. (cl-loop with args = (query-replace-read-args prompt regexp-flag t)
  668. for buf in bufs
  669. do
  670. (save-window-excursion
  671. (switch-to-buffer buf)
  672. (save-excursion
  673. (let ((case-fold-search t))
  674. (goto-char (point-min))
  675. (apply #'perform-replace
  676. (list (nth 0 args) (nth 1 args)
  677. t regexp-flag (nth 2 args) nil
  678. multi-query-replace-map))))))))
  679. (defun helm-buffer-query-replace-regexp (_candidate)
  680. (helm-buffer-query-replace-1 'regexp))
  681. (defun helm-buffer-query-replace (_candidate)
  682. (helm-buffer-query-replace-1))
  683. (defun helm-buffer-toggle-diff (candidate)
  684. "Toggle diff buffer CANDIDATE with it's file."
  685. (helm-aif (get-buffer-window "*Diff*" 'visible)
  686. (progn (kill-buffer "*Diff*")
  687. (set-window-buffer it helm-current-buffer))
  688. (let ((buf (get-buffer candidate)))
  689. (if (buffer-file-name buf)
  690. (diff-buffer-with-file buf)
  691. (user-error "Buffer `%s' is not associated to a file"
  692. (buffer-name buf))))))
  693. (defun helm-buffer-diff-persistent ()
  694. "Toggle diff buffer without quitting helm."
  695. (interactive)
  696. (with-helm-alive-p
  697. (helm-attrset 'diff-action 'helm-buffer-toggle-diff)
  698. (helm-execute-persistent-action 'diff-action)))
  699. (put 'helm-buffer-diff-persistent 'helm-only t)
  700. (defun helm-revert-buffer (candidate)
  701. (with-current-buffer candidate
  702. (helm-aif (buffer-file-name)
  703. (and (file-exists-p it) (revert-buffer t t)))))
  704. (defun helm-revert-marked-buffers (_ignore)
  705. (mapc 'helm-revert-buffer (helm-marked-candidates)))
  706. (defun helm-buffer-revert-and-update (_candidate)
  707. (with-helm-buffer
  708. (let ((marked (helm-marked-candidates))
  709. (preselect (helm-buffers--quote-truncated-buffer
  710. (helm-get-selection))))
  711. (cl-loop for buf in marked do (helm-revert-buffer buf))
  712. (when helm-marked-candidates (helm-unmark-all))
  713. (helm-update preselect))))
  714. (defun helm-buffer-revert-persistent ()
  715. "Revert buffer without quitting helm."
  716. (interactive)
  717. (with-helm-alive-p
  718. (helm-attrset 'revert-action '(helm-buffer-revert-and-update . never-split))
  719. (helm-execute-persistent-action 'revert-action)))
  720. (put 'helm-buffer-revert-persistent 'helm-only t)
  721. (defun helm-buffer-save-and-update (_candidate)
  722. (with-helm-buffer
  723. (let ((marked (helm-marked-candidates))
  724. (preselect (helm-get-selection nil t))
  725. (enable-recursive-minibuffers t))
  726. (cl-assert marked nil "No buffers need to be saved")
  727. (cl-loop for buf in marked do
  728. (with-current-buffer (get-buffer buf)
  729. (when (buffer-file-name) (save-buffer))))
  730. (when helm-marked-candidates (helm-unmark-all))
  731. (helm-update (regexp-quote preselect)))))
  732. (defun helm-buffer-save-some-buffers (_candidate)
  733. (helm-buffers-mark-similar-buffers-1 'mod)
  734. (helm-buffer-save-and-update nil))
  735. (defun helm-buffer-run-save-some-buffers ()
  736. "Save unsaved file buffers without quitting helm."
  737. (interactive)
  738. (with-helm-alive-p
  739. (helm-attrset 'save-some-action '(helm-buffer-save-some-buffers . never-split))
  740. (helm-execute-persistent-action 'save-some-action)))
  741. (put 'helm-buffer-run-save-some-buffers 'helm-only t)
  742. (defun helm-buffer-save-persistent ()
  743. "Save buffer without quitting helm."
  744. (interactive)
  745. (with-helm-alive-p
  746. (helm-attrset 'save-action '(helm-buffer-save-and-update . never-split))
  747. (helm-execute-persistent-action 'save-action)))
  748. (put 'helm-buffer-save-persistent 'helm-only t)
  749. (defun helm-buffers-rename-buffer (candidate)
  750. (with-current-buffer candidate
  751. (rename-buffer (helm-read-string "New name: " (buffer-name)) t)))
  752. (defun helm-buffer-run-rename-buffer ()
  753. "Run rename buffer action from `helm-source-buffers-list'."
  754. (interactive)
  755. (with-helm-alive-p
  756. (helm-exit-and-execute-action 'helm-buffers-rename-buffer)))
  757. (put 'helm-buffer-run-rename-buffer 'helm-only t)
  758. (defun helm-buffer-run-kill-persistent ()
  759. "Kill buffer without quitting helm."
  760. (interactive)
  761. (with-helm-alive-p
  762. (helm-attrset 'kill-action '(helm-buffers-persistent-kill . never-split))
  763. (helm-execute-persistent-action 'kill-action)))
  764. (put 'helm-buffer-run-kill-persistent 'helm-only t)
  765. (defun helm-kill-marked-buffers (_ignore)
  766. (let* ((bufs (helm-marked-candidates))
  767. (killed-bufs (cl-count-if 'kill-buffer bufs)))
  768. (when (buffer-live-p helm-buffer)
  769. (with-helm-buffer
  770. (setq helm-marked-candidates nil
  771. helm-visible-mark-overlays nil)))
  772. (message "Killed %s buffer(s)" killed-bufs)))
  773. (defun helm-buffer-run-kill-buffers ()
  774. "Run kill buffer action from `helm-source-buffers-list'."
  775. (interactive)
  776. (with-helm-alive-p
  777. (helm-exit-and-execute-action 'helm-kill-marked-buffers)))
  778. (put 'helm-buffer-run-kill-buffers 'helm-only t)
  779. (defun helm-buffer-run-grep ()
  780. "Run Grep action from `helm-source-buffers-list'."
  781. (interactive)
  782. (with-helm-alive-p
  783. (helm-exit-and-execute-action 'helm-grep-buffers)))
  784. (put 'helm-buffer-run-grep 'helm-only t)
  785. (defun helm-buffer-run-zgrep ()
  786. "Run Grep action from `helm-source-buffers-list'."
  787. (interactive)
  788. (with-helm-alive-p
  789. (helm-exit-and-execute-action 'helm-zgrep-buffers)))
  790. (put 'helm-buffer-run-zgrep 'helm-only t)
  791. (defun helm-buffer-run-query-replace-regexp ()
  792. "Run Query replace regexp action from `helm-source-buffers-list'."
  793. (interactive)
  794. (with-helm-alive-p
  795. (helm-exit-and-execute-action 'helm-buffer-query-replace-regexp)))
  796. (put 'helm-buffer-run-query-replace-regexp 'helm-only t)
  797. (defun helm-buffer-run-query-replace ()
  798. "Run Query replace action from `helm-source-buffers-list'."
  799. (interactive)
  800. (with-helm-alive-p
  801. (helm-exit-and-execute-action 'helm-buffer-query-replace)))
  802. (put 'helm-buffer-run-query-replace 'helm-only t)
  803. (defun helm-buffer-switch-other-window ()
  804. "Run switch to other window action from `helm-source-buffers-list'."
  805. (interactive)
  806. (with-helm-alive-p
  807. (helm-exit-and-execute-action 'helm-buffer-switch-buffers-other-window)))
  808. (put 'helm-buffer-switch-other-window 'helm-only t)
  809. (defun helm-buffer-switch-other-frame ()
  810. "Run switch to other frame action from `helm-source-buffers-list'."
  811. (interactive)
  812. (with-helm-alive-p
  813. (helm-exit-and-execute-action 'switch-to-buffer-other-frame)))
  814. (put 'helm-buffer-switch-other-frame 'helm-only t)
  815. (defun helm-buffers-switch-to-buffer-new-tab ()
  816. "Run switch to buffer in other tab action from `helm-source-buffers-list'."
  817. (interactive)
  818. (cl-assert (fboundp 'tab-bar-mode) nil "Tab-bar-mode not available")
  819. (with-helm-alive-p
  820. (helm-exit-and-execute-action 'switch-to-buffer-other-tab)))
  821. (put 'helm-buffers-switch-to-buffer-new-tab 'helm-only t)
  822. (defun helm-buffer-switch-buffers (_candidate)
  823. "Switch to buffer candidates and replace current buffer.
  824. If more than one buffer marked switch to these buffers in separate windows.
  825. If a prefix arg is given split windows vertically."
  826. (let ((buffers (helm-marked-candidates)))
  827. (helm-window-show-buffers buffers)))
  828. (defun helm-buffer-switch-buffers-other-window (_candidate)
  829. "Switch to marked buffers in other windows."
  830. (let ((buffers (helm-marked-candidates)))
  831. (helm-window-show-buffers buffers t)))
  832. (defun helm-buffer-run-ediff ()
  833. "Run ediff action from `helm-source-buffers-list'."
  834. (interactive)
  835. (with-helm-alive-p
  836. (helm-exit-and-execute-action 'helm-ediff-marked-buffers)))
  837. (put 'helm-buffer-run-ediff 'helm-only t)
  838. (defun helm-buffer-run-ediff-merge ()
  839. "Run ediff action from `helm-source-buffers-list'."
  840. (interactive)
  841. (with-helm-alive-p
  842. (helm-exit-and-execute-action 'helm-ediff-marked-buffers-merge)))
  843. (put 'helm-buffer-run-ediff-merge 'helm-only t)
  844. (defun helm-buffers-persistent-kill-1 (buffer-or-name)
  845. "Persistent action to kill buffer."
  846. (let ((buf (get-buffer buffer-or-name)) helm-buf-or-cur)
  847. (if (or (and (eql buf (get-buffer helm-current-buffer))
  848. (setq helm-buf-or-cur "helm-current-buffer"))
  849. (and (eql buf (get-buffer helm-buffer))
  850. (setq helm-buf-or-cur "helm-buffer")))
  851. (progn
  852. (message "Can't kill `%s' without quitting session" helm-buf-or-cur)
  853. (sit-for 1))
  854. (kill-buffer buf)
  855. (helm-delete-current-selection))))
  856. (defun helm-buffers--quote-truncated-buffer (buffer)
  857. (let ((bufname (and (bufferp buffer)
  858. (buffer-name buffer))))
  859. (when (and bufname
  860. (file-remote-p (with-current-buffer bufname
  861. default-directory)))
  862. (setq bufname (concat "@ " (helm-url-unhex-string bufname))))
  863. (when bufname
  864. (regexp-quote
  865. (if (and helm-buffer-max-length
  866. helm-buffer-details-flag)
  867. (helm-substring-by-width
  868. bufname helm-buffer-max-length
  869. "")
  870. bufname)))))
  871. (defun helm-buffers-persistent-kill (_buffer)
  872. (let ((marked (helm-marked-candidates))
  873. (sel (helm-get-selection)))
  874. (unwind-protect
  875. (cl-loop for b in marked
  876. do (progn
  877. ;; We need to preselect each marked because
  878. ;; helm-buffers-persistent-kill is deleting
  879. ;; current selection.
  880. (helm-preselect
  881. (format "^%s"
  882. (helm-buffers--quote-truncated-buffer b)))
  883. (helm-buffers-persistent-kill-1 b)
  884. (message nil)
  885. (helm--remove-marked-and-update-mode-line b)))
  886. (with-helm-buffer
  887. (setq helm-marked-candidates nil
  888. helm-visible-mark-overlays nil))
  889. (helm-force-update (helm-buffers--quote-truncated-buffer sel)))))
  890. (defun helm-buffers-list-persistent-action (candidate)
  891. (let ((current (window-buffer helm-persistent-action-display-window)))
  892. (if (or (helm-follow-mode-p)
  893. (eql current (get-buffer helm-current-buffer))
  894. (not (eql current (get-buffer candidate))))
  895. (switch-to-buffer candidate)
  896. (if (and helm-persistent-action-display-window
  897. (window-dedicated-p
  898. (next-window helm-persistent-action-display-window 1)))
  899. (delete-window helm-persistent-action-display-window)
  900. (switch-to-buffer helm-current-buffer)))))
  901. (defun helm-ediff-marked-buffers (_candidate &optional merge)
  902. "Ediff 2 marked buffers or CANDIDATE and `helm-current-buffer'.
  903. With optional arg MERGE call `ediff-merge-buffers'."
  904. (let ((lg-lst (length (helm-marked-candidates)))
  905. buf1 buf2)
  906. (cl-case lg-lst
  907. (0
  908. (error "Error:You have to mark at least 1 buffer"))
  909. (1
  910. (setq buf1 helm-current-buffer
  911. buf2 (cl-first (helm-marked-candidates))))
  912. (2
  913. (setq buf1 (cl-first (helm-marked-candidates))
  914. buf2 (cl-second (helm-marked-candidates))))
  915. (t
  916. (error "Error:Too many buffers marked!")))
  917. (if merge
  918. (ediff-merge-buffers buf1 buf2)
  919. (ediff-buffers buf1 buf2))))
  920. (defun helm-ediff-marked-buffers-merge (candidate)
  921. "Ediff merge `helm-current-buffer' with CANDIDATE.
  922. See `helm-ediff-marked-buffers'."
  923. (helm-ediff-marked-buffers candidate t))
  924. (defun helm-multi-occur-as-action (_candidate)
  925. "Multi occur action for `helm-source-buffers-list'.
  926. Can be used by any source that list buffers."
  927. (let ((helm-occur-always-search-in-current
  928. (if helm-current-prefix-arg
  929. (not helm-occur-always-search-in-current)
  930. helm-occur-always-search-in-current))
  931. (buffers (helm-marked-candidates))
  932. (input (cl-loop for i in (split-string (or (buffer-local-value
  933. 'helm-input-local
  934. (get-buffer helm-buffer))
  935. helm-pattern)
  936. " " t)
  937. thereis (and (string-match "\\`@\\(.*\\)" i)
  938. (match-string 1 i)))))
  939. (helm-multi-occur-1 buffers input)))
  940. (defun helm-buffers-run-occur ()
  941. "Run `helm-multi-occur-as-action' by key."
  942. (interactive)
  943. (with-helm-alive-p
  944. (helm-exit-and-execute-action 'helm-multi-occur-as-action)))
  945. (put 'helm-buffers-run-occur 'helm-only t)
  946. (defun helm-buffers-toggle-show-hidden-buffers ()
  947. (interactive)
  948. (with-helm-alive-p
  949. (let ((filter-attrs (helm-attr 'filtered-candidate-transformer
  950. helm-source-buffers-list)))
  951. (if (memq 'helm-shadow-boring-buffers filter-attrs)
  952. (helm-attrset 'filtered-candidate-transformer
  953. (cons 'helm-skip-boring-buffers
  954. (remove 'helm-shadow-boring-buffers
  955. filter-attrs))
  956. helm-source-buffers-list)
  957. (helm-attrset 'filtered-candidate-transformer
  958. (cons 'helm-shadow-boring-buffers
  959. (remove 'helm-skip-boring-buffers
  960. filter-attrs))
  961. helm-source-buffers-list))
  962. (helm-force-update))))
  963. (put 'helm-buffers-toggle-show-hidden-buffers 'helm-only t)
  964. (defun helm-buffers-browse-project (buf)
  965. "Browse project from buffer."
  966. (with-current-buffer buf
  967. (helm-browse-project helm-current-prefix-arg)))
  968. (defun helm-buffers-run-browse-project ()
  969. "Run `helm-buffers-browse-project' from key."
  970. (interactive)
  971. (with-helm-alive-p
  972. (if helm-buffers-in-project-p
  973. (user-error "You are already browsing this project")
  974. (helm-exit-and-execute-action 'helm-buffers-browse-project))))
  975. ;;; Candidate Transformers
  976. ;;
  977. ;;
  978. (defun helm-skip-boring-buffers (buffers _source)
  979. (helm-skip-entries buffers
  980. helm-boring-buffer-regexp-list
  981. helm-white-buffer-regexp-list))
  982. (defun helm-shadow-boring-buffers (buffers _source)
  983. "Buffers matching `helm-boring-buffer-regexp' will be
  984. displayed with the `file-name-shadow' face if available."
  985. (helm-shadow-entries buffers helm-boring-buffer-regexp-list))
  986. ;;;###autoload
  987. (defun helm-buffers-list ()
  988. "Preconfigured `helm' to list buffers."
  989. (interactive)
  990. (unless helm-source-buffers-list
  991. (setq helm-source-buffers-list
  992. (helm-make-source "Buffers" 'helm-source-buffers)))
  993. (helm :sources '(helm-source-buffers-list
  994. helm-source-ido-virtual-buffers
  995. helm-source-buffer-not-found)
  996. :buffer "*helm buffers*"
  997. :keymap helm-buffer-map
  998. :truncate-lines helm-buffers-truncate-lines
  999. :left-margin-width helm-buffers-left-margin-width))
  1000. ;;;###autoload
  1001. (defun helm-mini ()
  1002. "Preconfigured `helm' displaying `helm-mini-default-sources'."
  1003. (interactive)
  1004. (require 'helm-x-files)
  1005. (unless helm-source-buffers-list
  1006. (setq helm-source-buffers-list
  1007. (helm-make-source "Buffers" 'helm-source-buffers)))
  1008. (helm :sources helm-mini-default-sources
  1009. :buffer "*helm mini*"
  1010. :ff-transformer-show-only-basename nil
  1011. :truncate-lines helm-buffers-truncate-lines
  1012. :left-margin-width helm-buffers-left-margin-width))
  1013. (defun helm-quit-and-helm-mini ()
  1014. "Drop into `helm-mini' from `helm'."
  1015. (interactive)
  1016. (with-helm-alive-p
  1017. (helm-run-after-exit 'helm-mini)))
  1018. (provide 'helm-buffers)
  1019. ;; Local Variables:
  1020. ;; byte-compile-warnings: (not obsolete)
  1021. ;; coding: utf-8
  1022. ;; indent-tabs-mode: nil
  1023. ;; End:
  1024. ;;; helm-buffers.el ends here