Fix commentary.
[emacs.git] / lisp / pcmpl-linux.el
blobae6ec7dc12a78e0fbe341d79730c11e114e97bd0
1 ;;; pcmpl-linux.el --- functions for dealing with GNU/Linux completions
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; This file is part of GNU Emacs.
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 3, or (at your option)
11 ;; any later version.
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 ;; Boston, MA 02110-1301, USA.
23 ;;; Commentary:
25 ;; These functions are for use with GNU/Linux. Since they depend on a
26 ;; certain knowledge of the layout of such systems, they probably
27 ;; won't work very well on other operating systems.
29 ;;; Code:
31 (provide 'pcmpl-linux)
33 (require 'pcomplete)
35 (defgroup pcmpl-linux nil
36 "Functions for dealing with GNU/Linux completions."
37 :group 'pcomplete)
39 ;; Functions:
41 ;;;###autoload
42 (defun pcomplete/kill ()
43 "Completion for GNU/Linux `kill', using /proc filesystem."
44 (if (pcomplete-match "^-\\(.*\\)" 0)
45 (pcomplete-here
46 (pcomplete-uniqify-list
47 (split-string
48 (pcomplete-process-result "kill" "-l")))
49 (pcomplete-match-string 1 0)))
50 (while (pcomplete-here
51 (if (file-directory-p "/proc")
52 (let ((default-directory "/proc/"))
53 (mapcar 'directory-file-name
54 (pcomplete-entries "[0-9]+/$"))))
55 nil 'identity)))
57 ;;;###autoload
58 (defun pcomplete/umount ()
59 "Completion for GNU/Linux `umount'."
60 (pcomplete-opt "hVafrnvt(pcmpl-linux-fs-types)")
61 (while (pcomplete-here (pcmpl-linux-mounted-directories)
62 nil 'identity)))
64 ;;;###autoload
65 (defun pcomplete/mount ()
66 "Completion for GNU/Linux `mount'."
67 (pcomplete-opt "hVanfFrsvwt(pcmpl-linux-fs-types)o?L?U?")
68 (while (pcomplete-here (pcomplete-entries) nil 'identity)))
70 (defun pcmpl-linux-fs-types ()
71 "Return a list of available fs modules on GNU/Linux systems."
72 (let ((kernel-ver (pcomplete-process-result "uname" "-r")))
73 (mapcar
74 (function
75 (lambda (fsobj)
76 (substring fsobj 0 (- (length fsobj) 2))))
77 (let ((default-directory
78 (concat "/lib/modules/" kernel-ver "/fs/")))
79 (pcomplete-entries "\\.o$")))))
81 (defun pcmpl-linux-mounted-directories ()
82 "Return a list of mounted directory names."
83 (let (points)
84 (when (file-readable-p "/etc/mtab")
85 (with-temp-buffer
86 (insert-file-contents-literally "/etc/mtab")
87 (while (not (eobp))
88 (let* ((line (buffer-substring (point) (line-end-position)))
89 (args (split-string line " ")))
90 (setq points (cons (nth 1 args) points)))
91 (forward-line)))
92 (pcomplete-uniqify-list points))))
94 (defun pcmpl-linux-mountable-directories ()
95 "Return a list of mountable directory names."
96 (let (points)
97 (when (file-readable-p "/etc/fstab")
98 (with-temp-buffer
99 (insert-file-contents-literally "/etc/fstab")
100 (while (not (eobp))
101 (let* ((line (buffer-substring (point) (line-end-position)))
102 (args (split-string line "\\s-+")))
103 (setq points (cons (nth 1 args) points)))
104 (forward-line)))
105 (pcomplete-pare-list
106 (pcomplete-uniqify-list points)
107 (cons "swap" (pcmpl-linux-mounted-directories))))))
109 ;;; arch-tag: bb0961a6-a623-463d-92c6-497c317293b1
110 ;;; pcmpl-linux.el ends here