Skip to main content
added 2 characters in body
Source Link
oOosys
  • 505
  • 3
  • 12

Your question are actually two questions asked:

  • How can I show if a file has changed on disk?
  • How can I show a notification in the mode-line?

From what you provide as additional information:

I'm trying to troubleshoot why auto-revert doesn't work for me, and such an indication would help.

I conclude that the more important one and your actual question is:

How can I show if a file has changed on diskHow can I show if a file has changed on disk

One part required to arrive at a solution was already given in the comment to your question by Phil Hudson mentioning verify-visited-file-modtime . The missing part was how to run this function periodically and give a visual feedback if a file was modified by an external application.

The code below if placed in the initialization file does what you ask for:

(defun check-external-file-modification ()
  (if (verify-visited-file-modtime)
      nil
      (message "%s" "Info: BUFFER changed by external application")
  )
  (run-with-timer 5 nil 'check-external-file-modification)
)
(check-external-file-modification)

Notice that the value 5 in the code above means that the check is done each 5 seconds, but you can change it also to any (also a floating point) other value.

The notification about changed file status is shown each 5 seconds in the minibuffer and mirrored in *Messages*.

YouYour other question:

  • How can I show notifications in the mode-line?

is worth another question if the code you have written yourself for this purpose and for your specific Mode Line layout should for some reason not work as expected.

Your question are actually two questions asked:

  • How can I show if a file has changed on disk?
  • How can I show a notification in the mode-line?

From what you provide as additional information:

I'm trying to troubleshoot why auto-revert doesn't work for me, and such an indication would help.

I conclude that the more important one and your actual question is:

How can I show if a file has changed on disk

One part required to arrive at a solution was already given in the comment to your question by Phil Hudson mentioning verify-visited-file-modtime . The missing part was how to run this function periodically and give a visual feedback if a file was modified by an external application.

The code below if placed in the initialization file does what you ask for:

(defun check-external-file-modification ()
  (if (verify-visited-file-modtime)
      nil
      (message "%s" "Info: BUFFER changed by external application")
  )
  (run-with-timer 5 nil 'check-external-file-modification)
)
(check-external-file-modification)

Notice that the value 5 in the code above means that the check is done each 5 seconds, but you can change it also to any (also a floating point) other value.

The notification about changed file status is shown each 5 seconds in the minibuffer and mirrored in *Messages*.

You other question:

  • How can I show notifications in the mode-line?

is worth another question if the code you have written yourself for this purpose and for your specific Mode Line layout should for some reason not work as expected.

Your question are actually two questions asked:

  • How can I show if a file has changed on disk?
  • How can I show a notification in the mode-line?

From what you provide as additional information:

I'm trying to troubleshoot why auto-revert doesn't work for me, and such an indication would help.

I conclude that the more important one and your actual question is:

How can I show if a file has changed on disk

One part required to arrive at a solution was already given in the comment to your question by Phil Hudson mentioning verify-visited-file-modtime . The missing part was how to run this function periodically and give a visual feedback if a file was modified by an external application.

The code below if placed in the initialization file does what you ask for:

(defun check-external-file-modification ()
  (if (verify-visited-file-modtime)
      nil
      (message "%s" "Info: BUFFER changed by external application")
  )
  (run-with-timer 5 nil 'check-external-file-modification)
)
(check-external-file-modification)

Notice that the value 5 in the code above means that the check is done each 5 seconds, but you can change it also to any (also a floating point) other value.

The notification about changed file status is shown each 5 seconds in the minibuffer and mirrored in *Messages*.

Your other question:

  • How can I show notifications in the mode-line?

is worth another question if the code you have written yourself for this purpose and for your specific Mode Line layout should for some reason not work as expected.

rewritten the answer
Source Link
oOosys
  • 505
  • 3
  • 12

Inspired byYour question are actually two questions asked:

  • How can I show if a file has changed on disk?
  • How can I show a notification in the mode-line?

From what you provide as additional information:

I'm trying to troubleshoot why auto-revert doesn't work for me, and such an indication would help.

I conclude that the more important one and your actual question is:

How can I show if a file has changed on disk

One part required to arrive at a solution was already given in the comment to your question by Phil Hudson below a readymentioning verify-visited-file-modtime . The missing part was how to use solution you can start from yourrun this function periodically and give a visual feedback if a file was modified by an external application.

The code below if placed in the initialization file does what you ask for:

(defun check-external-file-modification ()
  (if (verify-visited-file-modtime)
      nil
      (message "%s" "Info: BUFFER changed by external application")
  )
  (run-with-timer 5 nil 'check-external-file-modification)
)
(check-external-file-modification)

Notice that the value 5 in the code above means that the check is rundone each 5 seconds. Change, but you can change it also to one second orany (also a floating point) other value for shorter time period.

I think that showing itThe notification about changed file status is shown each 5 seconds in the minibuffer is maybe even preferable over showing itand mirrored in *Messages*.

You other question:

  • How can I show notifications in the mode-line?

is worth another question if the modelinecode you have written yourself for this purpose and for your specific Mode Line layout should for some reason not work as expected.

Inspired by the comment to your question by Phil Hudson below a ready to use solution you can start from your initialization file:

(defun check-external-file-modification ()
  (if (verify-visited-file-modtime)
      nil
      (message "%s" "Info: BUFFER changed by external application")
  )
  (run-with-timer 5 nil 'check-external-file-modification)
)
(check-external-file-modification)

Notice that the check is run each 5 seconds. Change it to one second or a floating point value for shorter time period.

I think that showing it in the minibuffer is maybe even preferable over showing it in the modeline.

Your question are actually two questions asked:

  • How can I show if a file has changed on disk?
  • How can I show a notification in the mode-line?

From what you provide as additional information:

I'm trying to troubleshoot why auto-revert doesn't work for me, and such an indication would help.

I conclude that the more important one and your actual question is:

How can I show if a file has changed on disk

One part required to arrive at a solution was already given in the comment to your question by Phil Hudson mentioning verify-visited-file-modtime . The missing part was how to run this function periodically and give a visual feedback if a file was modified by an external application.

The code below if placed in the initialization file does what you ask for:

(defun check-external-file-modification ()
  (if (verify-visited-file-modtime)
      nil
      (message "%s" "Info: BUFFER changed by external application")
  )
  (run-with-timer 5 nil 'check-external-file-modification)
)
(check-external-file-modification)

Notice that the value 5 in the code above means that the check is done each 5 seconds, but you can change it also to any (also a floating point) other value.

The notification about changed file status is shown each 5 seconds in the minibuffer and mirrored in *Messages*.

You other question:

  • How can I show notifications in the mode-line?

is worth another question if the code you have written yourself for this purpose and for your specific Mode Line layout should for some reason not work as expected.

deleted 2 characters in body
Source Link
oOosys
  • 505
  • 3
  • 12

Inspired by the comment to your question by Phil Hudson below a ready to use solution you can start from your initialization file:

(defun check-external-file-modification ()
 
  (if (verify-visited-file-modtime)
      nil
      (message "%s" "Info: BUFFER changed by external application")
  )
  (run-with-timer 5 nil 'check-external-file-modification)
)
(check-external-file-modification)

Notice that the check is run each 5 seconds. Change it to one second or a floating point value for shorter time period.

I think that showing it in the minibuffer is maybe even preferable over showing it in the modeline.

Inspired by the comment to your question by Phil Hudson below a ready to use solution you can start from your initialization file:

(defun check-external-file-modification ()
 
  (if (verify-visited-file-modtime)
      nil
      (message "%s" "Info: BUFFER changed by external application")
  )
  (run-with-timer 5 nil 'check-external-file-modification)
)
(check-external-file-modification)

Notice that the check is run each 5 seconds. Change it to one second or a floating point value for shorter time period.

I think that showing it in the minibuffer is maybe even preferable over showing it in the modeline.

Inspired by the comment to your question by Phil Hudson below a ready to use solution you can start from your initialization file:

(defun check-external-file-modification ()
  (if (verify-visited-file-modtime)
      nil
      (message "%s" "Info: BUFFER changed by external application")
  )
  (run-with-timer 5 nil 'check-external-file-modification)
)
(check-external-file-modification)

Notice that the check is run each 5 seconds. Change it to one second or a floating point value for shorter time period.

I think that showing it in the minibuffer is maybe even preferable over showing it in the modeline.

Post Undeleted by oOosys
Post Deleted by oOosys
Source Link
oOosys
  • 505
  • 3
  • 12
Loading