Source

view-process / view-process-xemacs.el

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
;;; view-process-xemacs.el --- XEmacs specific code for view-process

;; Copyright (C) 1995, 1996 Heiko Muenkel

;; Author: Heiko Muenkel
;; Keywords: processes

;; This file is part of XEmacs.

;;  XEmacs is free software; you can redistribute it and/or modify it
;;  under the terms of the GNU General Public License as published by
;;  the Free Software Foundation; either version 2, or (at your
;;  option) any later version.

;;  XEmacs is distributed in the hope that it will be useful, but
;;  WITHOUT ANY WARRANTY; without even the implied warranty of
;;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;  General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with XEmacs; see the file COPYING.  If not, write to the Free
;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
;; 02111-1307, USA.

;;; Synched up with:  Emacs 20.1

;;; Commentary:

;;	This file contains lisp code which works only in the XEmacs.

;; Installation: 

;;	Put this file in one of your lisp load directories.
;;

;;; Code:

(provide 'view-process-xemacs)

;;; variables

(defvar View-process-itimer-name "view-process"
  "Name of the view-process itimer.")


;;; special keybindings

(define-key View-process-mode-map '(button2) 'View-process-mouse-kill)
(define-key View-process-mode-map '(button3) 'View-process-popup-menu)


;;; menus

(if (not View-process-pulldown-menu)
    (setq
     View-process-pulldown-menu
     '("View-process-pulldown-menu-name"
       ["Rename Buffer" View-process-rename-current-output-buffer t]
       ["Submit Bug Report" View-process-submit-bug-report t]
       ["Quit" View-process-quit t]
       ("Options"
	["Truncate Lines" 
	 View-process-toggle-truncate-lines 
	 :style toggle
	 :selected truncate-lines]
	["Motion Help"
	 View-process-toggle-motion-help
	 :style toggle
	 :selected View-process-motion-help]
	["Two Windows"
	 View-process-toggle-display-with-2-windows
	 :style toggle
	 :selected View-process-display-with-2-windows]
	["Hide Header"
	 View-process-toggle-hide-header
	 :style toggle
	 :selected View-process-hide-header
	 :active View-process-display-with-2-windows]
	["Digits Send Signals"
	 View-process-toggle-digit-bindings
	 :style toggle
	 :selected View-process-digit-bindings-send-signal]
	)
       )))


(if (not View-process-region-menu)
    (setq 
     View-process-region-menu
     '("PS Region Menu"
       ["View Processes" view-processes nil]
       ["New PS" View-process-status nil]
       ["Update" View-process-status-update nil]
       ("Periodic Output"
	["Start " 
	 View-process-start-itimer 
	 :style radio 
	 :selected (not (get-itimer View-process-itimer-name))
	 :active nil]	
	["Stop" 
	 View-process-delete-itimer 
	 :style radio 
	 :selected (get-itimer View-process-itimer-name)
	 :active nil]
	)
       ("Send Signal"
	["SIGHUP" 
	 (View-process-send-signal-to-processes-in-region "SIGHUP") t]
	["SIGTERM" 
	 (View-process-send-signal-to-processes-in-region "SIGTERM") t]
	["SIGKILL" 
	 (View-process-send-signal-to-processes-in-region "SIGKILL") t]
	["SIGSTOP" 
	 (View-process-send-signal-to-processes-in-region "SIGSTOP") t]
	["SIGCONT" 
	 (View-process-send-signal-to-processes-in-region "SIGCONT") t]
	["SIGQUIT" 
	 (View-process-send-signal-to-processes-in-region "SIGQUIT") t]
	"----"
	["Any Signal..." View-process-send-signal-to-processes-in-region t]
	"----"
	["Alter Priority..." View-process-renice-processes-in-region t]
	)
       ("Mark"
	["Mark" View-process-mark-current-line nil]
	["Mark Children" View-process-mark-children-in-current-line nil]
	["Remark Last Marks" View-process-reset-last-marks nil]
	"----"
	["Unmark" View-process-unmark-current-line nil]
	["Unmark All" View-process-unmark-all nil]
	)
       "----"
       ["Sort" View-process-sort-region-by-current-field (looking-at "[^ ]")]
       ["Reverse" View-process-reverse-region t]
       ["Field Filter..." 
	View-process-filter-region-by-current-field 
	(looking-at "[^ ]")]
       ["Exclude Field Filter..." 
	(progn (setq current-prefix-arg '(-1))
	       (call-interactively 
		'View-process-filter-region-by-current-field))
	:keys "C-u -1 M-c f"
	:active (looking-at "[^ ]")]	    
       ["Line Filter..." View-process-filter-region t]
       ["Exclude Line Filter..." 
	(progn (setq current-prefix-arg '(-1))
	       (call-interactively 
		'View-process-filter-region))
	:keys "C-u -1 M-c g"
	:active t]
       "----"
       ("Help"
	["PID and Command" View-process-show-pid-and-command nil]
	["Field Name" View-process-which-field-name nil]
	["Header Line" View-process-show-header-line nil]
	["Own PID" View-process-display-emacs-pid nil]
	)
       )
     )
  )

(if (not View-process-marked-menu)
    (setq 
     View-process-marked-menu
     '("PS Marked Menu"
       ["View Processes" view-processes t]
       ["New PS" View-process-status t]
       ["Update" View-process-status-update t]
       ("Periodic Output"
	["Start " 
	 View-process-start-itimer 
	 :style radio 
	 :selected (not (get-itimer View-process-itimer-name))
	 :active nil]
	["Stop" 
	 View-process-delete-itimer 
	 :style radio 
	 :selected (get-itimer View-process-itimer-name)
	 :active nil]
	)
       ("Send Signal"
	["SIGHUP" (View-process-send-signal-to-processes-with-mark "SIGHUP") t]
	["SIGTERM" 
	 (View-process-send-signal-to-processes-with-mark "SIGTERM") 
	 t]
	["SIGKILL" 
	 (View-process-send-signal-to-processes-with-mark "SIGKILL") 
	 t]
	["SIGSTOP" 
	 (View-process-send-signal-to-processes-with-mark "SIGSTOP") 
	 t]
	["SIGCONT" 
	 (View-process-send-signal-to-processes-with-mark "SIGCONT") 
	 t]
	["SIGQUIT" 
	 (View-process-send-signal-to-processes-with-mark "SIGQUIT") 
	 t]
	"----"
	["Any Signal..." View-process-send-signal-to-processes-with-mark t]
	"----"
	["Alter Priority..." View-process-renice-processes-with-mark t]
	)
       ("Mark"
	["Mark" View-process-mark-current-line t]
	["Mark Children" View-process-mark-children-in-current-line t]
	["Remark Last Marks" View-process-reset-last-marks t]
	"----"
	["Unmark" View-process-unmark-current-line t]
	["Unmark All" View-process-unmark-all t]
	)
       "----"
       ["Sort" View-process-sort-output-by-current-field (looking-at "[^ ]")]
       ["Reverse" View-process-reverse-output t]
       ["Field Filter..." 
	View-process-filter-output-by-current-field (looking-at "[^ ]")]
       ["Exclude Field Filter..." 
	(progn (setq current-prefix-arg '(-1))
	       (call-interactively 
		'View-process-filter-output-by-current-field))
	:keys "C-u -1 F"
	:active (looking-at "[^ ]")]	    
       ["Line Filter..." View-process-filter-output t]
       ["Exclude Line Filter..." 
	(progn (setq current-prefix-arg '(-1))
	       (call-interactively 
		'View-process-filter-output))
	:keys "C-u -1 G"
	:active t]	    
       "----"
       ("Help"
	["PID and Command" View-process-show-pid-and-command t]
	["Field Name" View-process-which-field-name (looking-at "[^ ]")]
	["Header Line" View-process-show-header-line t]
	["Own PID" View-process-display-emacs-pid t]
	)
       )
     )
  )

(if (not View-process-non-region-menu)
    (setq 
     View-process-non-region-menu
     '("PS Non Region Menu"
       ["View Processes" view-processes t]
       ["New PS" View-process-status t]
       ["Update" View-process-status-update t]
       ("Periodic Output"
	["Start " 
	 View-process-start-itimer 
	 :style radio 
	 :selected (not (get-itimer View-process-itimer-name))]
	["Stop" 
	 View-process-delete-itimer 
	 :style radio 
	 :selected (get-itimer View-process-itimer-name)]
	)
       ("Send Signal"
	["SIGHUP" (View-process-send-signal-to-process-in-line "SIGHUP") t]
	["SIGTERM" (View-process-send-signal-to-process-in-line "SIGTERM") t]
	["SIGKILL" (View-process-send-signal-to-process-in-line "SIGKILL") t]
	["SIGSTOP" (View-process-send-signal-to-process-in-line "SIGSTOP") t]
	["SIGCONT" (View-process-send-signal-to-process-in-line "SIGCONT") t]
	["SIGQUIT" (View-process-send-signal-to-process-in-line "SIGQUIT") t]
	"----"
	["Any Signal..." View-process-send-signal-to-process-in-line t]
	"----"
	["Alter Priority..." View-process-renice-process-in-line t]
	)
       ("Mark"
	["Mark" View-process-mark-current-line t]
	["Mark Children" View-process-mark-children-in-current-line t]
	["Remark Last Marks" View-process-reset-last-marks t]
	"----"
	["Unmark" View-process-unmark-current-line nil]
	["Unmark All" View-process-unmark-all nil]
	)
       "----"
       ["Sort" View-process-sort-output-by-current-field (looking-at "[^ ]")]
       ["Reverse" View-process-reverse-output t]
       ["Field Filter..." 
	View-process-filter-output-by-current-field 
	(looking-at "[^ ]")]
       ["Exclude Field Filter..." 
	(progn (setq current-prefix-arg '(-1))
	       (call-interactively 
		'View-process-filter-output-by-current-field))
	:keys "C-u -1 F"
	:active (looking-at "[^ ]")]	    
       ["Line Filter..." View-process-filter-output t]
       ["Exclude Line Filter..." 
	(progn (setq current-prefix-arg '(-1))
	       (call-interactively 
		'View-process-filter-output))
	:keys "C-u -1 G"
	:active t]	    
       "----"
       ("Help"
	["PID and Command" View-process-show-pid-and-command t]
	["Field Name" View-process-which-field-name (looking-at "[^ ]")]
	["Header Line" View-process-show-header-line t]
	["Own PID" View-process-display-emacs-pid t]
	)
       )
     )
  )

(defun View-process-popup-menu (event)
  "Pops up a menu for the `View-process-mode'."
  (interactive "e")
  (mouse-set-point event)
  (popup-menu
   (cond ((View-process-region-active-p) View-process-region-menu)
	 (View-process-pid-mark-alist View-process-marked-menu)
	 (t View-process-non-region-menu))))

(defun View-process-install-pulldown-menu ()
  "Installs a pulldown menu for the `View-process-mode'."
  (if (and (featurep 'menubar)
	   current-menubar 
	   (not (assoc View-process-pulldown-menu-name current-menubar)))
      (progn
	(set-buffer-menubar (copy-sequence current-menubar))
	(add-submenu nil
		     (cons View-process-pulldown-menu-name
			   (cdr View-process-pulldown-menu)))
	(add-submenu (list View-process-pulldown-menu-name)
		     View-process-region-menu
		     "Submit Bug Report")
	(add-submenu (list View-process-pulldown-menu-name)
		     View-process-marked-menu
		     "Submit Bug Report")
	(add-submenu (list View-process-pulldown-menu-name)
		     View-process-non-region-menu
		     "Submit Bug Report")
	)))


;;; mode motion

(defun View-process-mode-motion-highlight-line (event)
  "For use as the value of `mode-motion-hook' in the `View-process-mode'.
It highlights the line under the mouse and displays help messages during
mouse motion, if `View-process-motion-help' is non nil."
  (if (and (event-point event)
	   (> (event-point event) View-process-header-end))
      (progn
	(mode-motion-highlight-line event)
	(if (and View-process-motion-help
		 (not View-process-stop-motion-help))
	    (save-excursion
		(mouse-set-point event)
		(View-process-show-pid-and-command-or-field-name)
		)))
    (message "")
    ))

(defun View-process-install-mode-motion ()
  "Installs the `mode-motion-hook'."
  (make-local-variable 'mode-motion-hook)
  (setq mode-motion-hook 'View-process-mode-motion-highlight-line))

(defun View-process-toggle-motion-help (&optional arg)
  "Change whether a help message is displayed during mouse motion.
With a positive ARG the variable 'View-process-motion-help' is set
to t and with a negative ARG it is set to nil."
  (interactive "P")
  (if arg
      (if (>= (prefix-numeric-value arg) 0)
	  (setq View-process-motion-help t)
	(setq View-process-motion-help nil))
    (if View-process-motion-help
	(setq View-process-motion-help nil)
      (setq View-process-motion-help t))))

; necessary for the Emacs 19
(defalias 'View-process-insert-and-inherit 'insert)

;;; timer functions

(defun View-process-start-itimer ()
  "Starts or restarts the itimer for updating the process output."
  (interactive)
  (if (get-itimer View-process-itimer-name)
      (progn 
	(set-itimer-value (get-itimer View-process-itimer-name) 
			  View-process-itimer-value)
	(set-itimer-restart (get-itimer View-process-itimer-name)
			    View-process-itimer-value))
    (start-itimer View-process-itimer-name
		  'View-process-status-itimer-function
		  View-process-itimer-value
		  View-process-itimer-value)))

(defun View-process-delete-itimer ()
  "Stops (deletes) the view process itimer."
  (interactive)
  (if (get-itimer View-process-itimer-name)
      (delete-itimer View-process-itimer-name)))


;;; region

(defun View-process-region-active-p ()
  "Returns t, if a region is active.
If `zmacs-regions' is nil, then this return always nil."
  (if zmacs-regions
      (mark)))


;;; Misc

(defun View-process-return-current-command-key-as-string ()
  "Returns the key, which invokes the current command as string."
  (events-to-keys (this-command-keys)))

(defun View-process-redraw ()
  "Dummy function. It does nothing in XEmacs."
  )


;;; font-lock and colors

(defun View-process-install-font-lock ()
  "Installs the `font-lock-mode', if `View-process-use-font-lock' is t."
  (if View-process-use-font-lock
      (font-lock-mode 1)))

(if (not (fboundp 'valid-color-name-p))
    (defalias 'valid-color-name-p 'x-valid-color-name-p))

(defun View-process-search-color-in-color-list (color-list)
  "Searches a valid color in the COLOR-LIST."
  (cond ((not color-list) nil)
	((listp color-list)
	 (if (valid-color-name-p (car color-list))
	     (car color-list)
	   (View-process-search-color-in-color-list (cdr color-list))))))

(defun View-process-search-color (color)
  "It returns a color, which could be displayed by the window manager.
COLOR is either a string with a color or a list with possible
colors."
  (cond ((not color) nil)
	((stringp color)
	 (if (valid-color-name-p color) color nil))
	((listp color)
	 (View-process-search-color-in-color-list color))
	(t nil)))
  
;;; missing function window-pixel-edges in XEmacs < 19.12
;;; Attention: This emulation is only valid, to test if a value 
;;; is 0 or not.
(if (not (fboundp 'window-pixel-edges))
    (defalias 'window-pixel-edges 'window-edges))


;;; Modeline 

(if (fboundp 'set-specifier)

(defun view-process-switch-buffer-modeline (modeline-on)
  "Switches the current modeline on, if MODELINE-ON is t.
Otherwise the modeline is switched off."
  (set-specifier has-modeline-p (cons (current-buffer) modeline-on)))


(defun view-process-switch-buffer-modeline (modeline-on)
  "Dummy function. 
Sorry, the modeline can't be switched off in this emacs version.
You have to update at least to XEmacs 19.12."
  )

)

;;; view-process-xemacs.el ends here.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.